
以下是以sql server为例来说明:
select b.stu_name,
max(case a.subject when '语文' then a.grade else '' end) as 语文,
max(case a.subject when '数学' then a.grade else '' end) as 数学,
max(case a.subject when '英语' then a.grade else '' end) as 英语
from stu_grade a,stu_master b
where a.stu_no=b.stu_no
group by b.stu_name
数据库为oralce的话执行
select b.stu_name,
max(case a.subject when '语文' then to_char(a.grade) else '' end) as 语文,
max(case a.subject when '数学' then to_char(a.grade) else '' end) as 数学,
max(case a.subject when '英语' then to_char(a.grade) else '' end) as 英语
from stu_grade a,stu_master b
where a.stu_no=b.stu_no
group by b.stu_name
是这个意思吗?
SUM(CASE WHEN W.TypeID = 999 AND (SUM(CASE WHEN W.TypeID = 999 AND BDate='2014-04-02' THEN BValue ELSE 0 end) as EndingBalance)='2014-04-02' THEN BValue ELSE 0 end) as EndingBalance
请详细描述一下需求
查数据库一个表中的一个行的不同项,肯定要用到【Group By】语法。
示例1:
查询A列,在表Table_temp中不同项
select A from Table_temp group by a示例2:
查询A列,在表Table_temp中不同项出现的次数
select A,count(0) as 出现次数 from Table_temp group by a欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)