select userid,(case when xkname='语文' then cj end) as '语文', (case when xkname='数学' then cj end) as '数学', (case when xkname='英语' then cj end) as '数学', (case when xkname='物理' then cj end) as '物理', (case when xkname='化学' then cj end) as '化学' from tb group by userid
也可以用SP生成字符串累计生成SQL语句的方法
http://blog.csdn.net/acmain_chm/article/details/4283943 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...
(case when xkname='数学' then cj end) as '数学',
(case when xkname='英语' then cj end) as '数学',
(case when xkname='物理' then cj end) as '物理',
(case when xkname='化学' then cj end) as '化学'
from tb
group by userid
在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解决方法,特发贴集思广义。http://topic.csdn.net/u/20090530/23/0b782674-4b0b-4cf5-bc1a-e8914aaee5ab.html?96198现整理解法如下:数据样本: create table tx( id int primary key, c1 c...