如何通过指定列求和 [英] How to sum the column order by specify column

查看:162
本文介绍了如何通过指定列求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表中有以下内容

In my table has following

sno      date           desc            amt       credit        debit  total 
2	08/02/2012	PURCHASE A/C	23	  34500.00	0.00		
2	08/02/2012	SOMU	23	0.00	  34500.00	NULL	
3	08/02/2012	SALES A/C	24	  0.00	        6000.00	NULL	
3	08/02/2012	DEVA	24	0	  0.00	        NULL	NULL
4	08/03/2012	SBI	14	0.00	  1000.00	NULL	NULL
4	08/03/2012	Cash A/c	14	  1000.00	0.00	NULL	
4	08/03/2012	Cash A/c	14	  1000.00	0.00	NULL	
4	08/03/2012	Cash A/c	14	  1000.00	0.00	NULL	



我想按日期对借方金额"和贷方金额"组求和?



I want to sum of the Debit amount and Credit amount group by date how to do it?

sno      date           desc            amt       credit        debit  total 
2	08/02/2012	PURCHASE A/C	23	  34500.00	0.00		
2	08/02/2012	SOMU	23	0.00	  34500.00	NULL	
3	08/02/2012	SALES A/C	24	  0.00	        6000.00	NULL	
3	08/02/2012	DEVA	24	6000.00	  0.00	        NULL	NULL
4       08/02/2012      Total           null      69000         6000    null
5       08/02/2012      balance         null      9000          null    null
4	08/03/2012	SBI	14	0.00	  1000.00	NULL	NULL
4	08/03/2012	Cash A/c	14	  1000.00	0.00	NULL	
4	08/03/2012	Cash A/c	14	  1000.00	0.00	NULL	
4	08/03/2012	Cash A/c	14	  1000.00	0.00	NULL
5    08/03/2012        Total           null      4000          0.00	null
 6     08/03/2012       balance         null      4000          0.00    null 


如何按日期获取订单的总金额.
谢谢


How to get the total amount for order by date.
Thank you

推荐答案

从表中选择日期,总和(借方),总和(贷方)
按日期分组
select date, sum(debit), sum(credit) from table
group by date


With CTE_Test
as
(select sno,[date],[desc],amt,creit,debit,Total,Row_number() over (PARTITION By date order by sno) as rowno
from temp_Table
union all
Select MAX(sno)+1,[date],'Total',null,SUM(creit),SUM(Debit),Null,1 from temp_table group by [date]
union all
Select MAX(sno)+2,[date],'Balance',null,SUM(creit)-SUM(Debit),null,Null,1 from temp_table group by [date])
Select * from cte_test order by date,sno


这篇关于如何通过指定列求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆