create table test(
f1 varchar(20),
f2 integer,
f3 varchar(20)
);insert into test(f1,f2,f3) values('aa','1','111111');
insert into test(f1,f2,f3) values('bb','1','222222');
insert into test(f1,f2,f3) values('cc','1','333333');
insert into test(f1,f2,f3) values('dd','1','444444');
insert into test(f1,f2,f3) values('ee','1','555555');
insert into test(f1,f2,f3) values('aa','2','aaaaaa');
insert into test(f1,f2,f3) values('dd','2','bbbbbb');我想得到的查询结果是下面这样的第一列 第二列 第三列aa 111111 aaaaaa
bb 222222
cc 333333
dd 444444 bbbbbb
ee 555555
max(if(f2=1,f3,null)),
max(if(f2=2,f3,null))
from test
group by f1
MySQL交叉表
在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解决方法,特发贴集思广义。http://topic.csdn.net/u/20090530/23/0b782674-4b0b-4cf5-bc1a-e8914aaee5ab.html?96198现整理解法如下:数据样本: create table tx( id int primary key, c1 c...