一个group by语句结果是
名称 数量
a 12
b 11
c 23
d 33
相让查询结果这样显示如何写SQL语句。
a b c d
12 11 23 33
名称 数量
a 12
b 11
c 23
d 33
相让查询结果这样显示如何写SQL语句。
a b c d
12 11 23 33
解决方案 »
- 面试 一次打击
- 请教CheckBoxList的SelectedIndexChanged事件?
- Server.Transfer传递页面后,能获得上一页面的DataList数据源吗?
- 时间问题~速度~下班前结帖~~~~~~~
- 小女求助,系统、数据库设计过程以及测试描述等
- 连动DropDownList的问题
- 如何配置IIS6,让扩展名为 .abc的文件其实是 .aspx的文件来使用
- start 学习ASP.NET
- asp中的语句:set objHttp = Server.CreateObject("MSXML2.ServerXMLHTTP") 用vb.net怎么写啊,我直接用报错
- C#和vb.net如何互相调用?
- 求个asp.net存取图片问题例子
- 请问如何在xsl+xml页面中引入css文件
b = case when 名称 = 'b' then 数量 else 0 end,
c = case when 名称 = 'c' then 数量 else 0 end,
d = case when 名称 = 'd' then 数量 else 0 end
From (group by语句结果)
数量=sum(case when 名称='a' then 数量 else 0 end),
数量=sum(case when 名称='b' then 数量 else 0 end),
数量=sum(case when 名称='c' then 数量 else 0 end),
数量=sum(case when 名称='d' then 数量 else 0 end)
from 表名
group by 名称
declare @s varchar(8000)
set @s =''
select @s = @s
+','+名称+' = max(case 名称 when '''+名称+''' then 数量 else 0 end )'
from tb
set @s= stuff(@s,1,1,'')
exec('select '+@s+'from tb group by 名称')
2 2005001 数学 90.0
3 2005001 英语 80.0
4 2005002 语文 56.0
5 2005002 数学 69.0
6 2005002 英语 89.0执行select sid,语文=isnull(sum(case course when '语文' then result end),0),
数学=isnull(sum(case course when '数学' then result end),0),
英语=isnull(sum(case course when '英语' then result end),0)
from result
group by sid
order by sid 得出结果sid 语文 数学 英语 2005001 80.0 90.0 80.0
2005002 56.0 69.0 89.0