内连接、左右连接:
参见: http://www.cnblogs.com/eflylab/archive/2007/06/25/794278.html
行列转换:
create table test_course(name varchar(20),subject varchar(20),score int);
insert into test_course values('Jack','Java',81);
insert into test_course values('Jack','C',71);
insert into test_course values('Alex','Java',66);
insert into test_course values('Alex','C',99);
insert into test_course values('Tom','Java',33);
insert into test_course values('Tom','C',88);
SELECT * FROM test.test_course;
转换:
select distinct(name),
(select score from test_course where subject='Java' and name = t1.name) as java,
(select score from test_course where subject='C' and name = t1.name) as C
from test_course as t1;
参考网页:
http://qsrock.iteye.com/blog/244241
http://hi.baidu.com/qzrc/blog/item/952686184634e0b44aedbcea.html
http://www.cppblog.com/lilac/archive/2008/01/13/41069.html
http://www.cnblogs.com/zitsing/archive/2012/03/05/2380901.html
对于最后一个网页:
如果是oracle数据库,下面的sql如何呢,一个童鞋建议到,如果有可以利用的函数 可以使用:
select 编号, sum(decode(类型,1,数值)) as 上旬, sum(decode(类型,2,数值)) 中旬, sum(decode(类型,3,数值)) 下旬 from t group by 编号