以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  求助一条sql语句写法!  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=90826)

--  作者:有点蓝
--  发布时间:2016/9/22 14:43:00
--  
什么数据库?
--  作者:有点蓝
--  发布时间:2016/9/22 14:59:00
--  
sel ect 备注,SUM(分数) as 分数 from (sel ect (case when 备注 like \'%a%\' then \'a\' when 备注 like \'%b%\' then \'b\' when 备注 like \'%c%\' then \'c\' end) as 备注,分数 from 表A) as a group by 备注
--  作者:有点蓝
--  发布时间:2016/9/22 15:51:00
--  
 se lect SUM(a) as a,SUM(b) as b,SUM(c) as c from (
  se lect (a.分数) as a,(b.分数) as b,(c.分数) as c
 from {表A} t
left join (s elect 备注,分数 from {表A} where 备注 like \'%a%\') as a on a.备注 = t.备注
left join (se lect 备注,分数 from {表A} where 备注 like \'%b%\') as b on b.备注 = t.备注
left join (sel ect 备注,分数 from {表A} where 备注 like \'%c%\') as c on c.备注 = t.备注) k

--  作者:jspta
--  发布时间:2016/9/22 16:01:00
--  
要用pivot功能,比较复杂,如果列数不固定,要合成SQL语句