问题描述
- 数据库查询,分组查询
-
这是要查的数据所对应的表,下边是sql
SELECT SUM(DECODE
(t.SUBJECT_TYPE,'zc',t.CASH_AMOUNT,0)) AS zcAmount,
SUM(DECODE (t.SUBJECT_TYPE,'fz',t.CASH_AMOUNT,0)) AS fzAmount,
SUM(DECODE (t.SUBJECT_TYPE,'qy',t.CASH_AMOUNT,0)) AS qyAmount,
SUM(DECODE (t.SUBJECT_TYPE,'sr',t.CASH_AMOUNT,0)) AS srAmount,
SUM(DECODE (t.SUBJECT_TYPE,'cb',t.CASH_AMOUNT,0)) AS cbAmount
FROM T_CBPS_ACCOUNT_HIS t where t.ACCOUNT_DATE ='20150909'问题来了,因为表中account_currency字段是不同的,我现在怎么在根据这个字段在上边的基础上进行分组查询. 而且字段account_currency中的01,12什么的都是从代码中传过来的。谢谢大伙儿。
解决方案
SELECT Cname ,Grade
FROM SC,Courses
WHERE SC.Cno=Courses.Cno ?AND Sno=’2011247’;
SELECT ?Students.Sno,Grade
FROM SC,Students
WHERE ?Students.Sno=SC.Sno AND ?Cno=’CS202’AND Grade>90;
SELECT ?Stud......
答案就在这里:数据库分组查询
解决方案二:
SELECT SUM(DECODE
(t.SUBJECT_TYPE,'zc',t.CASH_AMOUNT,0)) AS zcAmount,
SUM(DECODE (t.SUBJECT_TYPE,'fz',t.CASH_AMOUNT,0)) AS fzAmount,
SUM(DECODE (t.SUBJECT_TYPE,'qy',t.CASH_AMOUNT,0)) AS qyAmount,
SUM(DECODE (t.SUBJECT_TYPE,'sr',t.CASH_AMOUNT,0)) AS srAmount,
SUM(DECODE (t.SUBJECT_TYPE,'cb',t.CASH_AMOUNT,0)) AS cbAmount
FROM T_CBPS_ACCOUNT_HIS t where t.ACCOUNT_DATE ='20150909'
GROUP BY account_currency
时间: 2024-11-05 17:27:46