如何按日期在SQL查询组中使用Max for sum [英] How do I use Max for sum in a SQL Query group by Date

查看:234
本文介绍了如何按日期在SQL查询组中使用Max for sum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,



在表格中,PaymentDetails每天都有maney行一年。我希望明确总金额日期,并希望得到一年中的最大金额(每天的总和)。



示例:

Dear Sir,

In a table PaymentDetails there are maney rows in each day for a year. I want to sum total amount date wise and want to get maximum amount(sum of each days) of the year.

Example :

select max(AmtSUM),sum(TPaidAmt) from Vw_PaymentDetails where FY_Code='1415' group by E_date





TPaidAmt :金额的ColumnName

AmtSUM sum(TPaidAmt)



请纠正代码,使其返回当天的最大值。



TPaidAmt : ColumnName of Amount
AmtSUM : sum(TPaidAmt)

Please rectify the code so that it return the maximum value of the day.

推荐答案

如果你想获得<单个日期的code> MAX 值,试试这个:

If you want to get MAX value for single date, try this:
SELECT E_date, MAX(TPaidAmt)
FROM Vw_PaymentDetails
--WHERE FY_Code='1415'
GROUP BY E_date





但是,如果你想获得 MAX SUM(金额)的值,试试这个:



But, if you want to get MAX value for SUM(of Amount), try this:

SELECT E_date, MAX(AmtSUM) AS MaxOfAmtSum
FROM (
     SELECT E_date, UM(TPaidAmt) AS AmtSUM
     FROM Vw_PaymentDetails
     GROUP BY E_date
) AS T
--WHERE FY_Code='1415'


这篇关于如何按日期在SQL查询组中使用Max for sum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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