本人 SQL 语句求SUM
原语句
select DISTINCT (nvl((select sum(a.FIRST_MONEY)
from account d,acc_page_blc a,acc_page b where a.head_id=b.id and b.acc_id=d.id and d.id = 28 group by d.dept_id,d.name,d.subject),0) +nvl((select sum(a.FIRST_MONEY)
from account d,acc_page_blc a,acc_page b where a.head_id=b.id and b.acc_id=d.id and d.id = 29 group by d.dept_id,d.name,d.subject),0)+nvl((select sum(a.FIRST_MONEY)
from account d,acc_page_blc a,acc_page b where a.head_id=b.id and b.acc_id=d.id and d.id = 30 group by d.dept_id,d.name,d.subject),0)
) as HJ,d.dept_id as entry_id,'小计',d.subject,a.month as month
from account d,acc_page_blc a,acc_page b where rownum <=1 group by d.dept_id,d.name,d.subject,a.month这个语句求出来的SUM 是没法按照 字段MONTH 这个字段 来分开月份的他所求合是所有月份的合 本人 在里边要加变量:a_MONTH
必须在
DISTINCT (nvl((select sum(a.FIRST_MONEY),
from account d,acc_page_blc a,acc_page b where a.head_id=b.id and b.acc_id=d.id and d.id = 28 group by d.dept_id,d.name,d.subject),0)
这个句子里边加 as HJ,d.dept_id as entry_id,'小计',d.subject,a.month as month 这几个别名字段 形成这个语句
原语句
select DISTINCT (nvl((select sum(a.FIRST_MONEY)
from account d,acc_page_blc a,acc_page b where a.head_id=b.id and b.acc_id=d.id and d.id = 28 group by d.dept_id,d.name,d.subject),0) +nvl((select sum(a.FIRST_MONEY)
from account d,acc_page_blc a,acc_page b where a.head_id=b.id and b.acc_id=d.id and d.id = 29 group by d.dept_id,d.name,d.subject),0)+nvl((select sum(a.FIRST_MONEY)
from account d,acc_page_blc a,acc_page b where a.head_id=b.id and b.acc_id=d.id and d.id = 30 group by d.dept_id,d.name,d.subject),0)
) as HJ,d.dept_id as entry_id,'小计',d.subject,a.month as month
from account d,acc_page_blc a,acc_page b where rownum <=1 group by d.dept_id,d.name,d.subject,a.month这个语句求出来的SUM 是没法按照 字段MONTH 这个字段 来分开月份的他所求合是所有月份的合 本人 在里边要加变量:a_MONTH
必须在
DISTINCT (nvl((select sum(a.FIRST_MONEY),
from account d,acc_page_blc a,acc_page b where a.head_id=b.id and b.acc_id=d.id and d.id = 28 group by d.dept_id,d.name,d.subject),0)
这个句子里边加 as HJ,d.dept_id as entry_id,'小计',d.subject,a.month as month 这几个别名字段 形成这个语句
from account d,acc_page_blc a,acc_page b where a.head_id=b.id and b.acc_id=d.id and d.id = 28 group by d.dept_id,d.name,d.subject)但是系统回答不是单一子查询 那个大哥能帮我把这个语句写通啊
然后再把你要的结果格式列出来,你的SQL看的头晕呀
2 340.2 82 其他材料油类账 油类 2008.07
3 -56.7 82 其他材料油类账 油类 2008.08
4 82 其他材料文具类帐 文具类
5 19972 82 其他材料文具类帐 文具类 2008.07
6 3624 82 其他材料文具类帐 文具类 2008.08
7 82 其他材料印刷类账 印刷类
8 113663 82 其他材料印刷类账 印刷类 2008.07
9 20822 82 其他材料印刷类账 印刷类 2008.08
10 158366 82 小计 印刷类 2008.07 这个数据是求的所有月份的合的我希望能求7月的 按照月份划分