Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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 :
SQL
select max(AmtSUM),sum(TPaidAmt) from Vw_PaymentDetails where FY_Code='1415' group by E_date


TPaidAmt : ColumnName of Amount
AmtSUM : sum(TPaidAmt)

Please rectify the code so that it return the maximum value of the day.
Posted
Updated 27-Sep-15 8:28am
v3
Comments
CHill60 25-Sep-15 8:30am    
So you need to GROUP the data. However it is very difficult to help you without any sample data, expected results and without seeing the code you have already tried
CHill60 25-Sep-15 10:30am    
Sample data? Expected results?
Where is AmtSum coming from?

1 solution

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


But, if you want to get MAX value for SUM(of Amount), try this:
SQL
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'
 
Share this answer
 
v2
Comments
[no name] 27-Sep-15 14:50pm    
A 5. BTW. this was a Q for me. You have to concentrate on more difficult Qs with Pivot and similar ;)
Bruno
Maciej Los 27-Sep-15 14:52pm    
Thank you, Bruno. I'll promise to respect your suggestion ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900