Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear all,

I have table such as:

InVoice table
======
ID int
Date datetime
Money double


* Case A:
Select ID, Money
from InVoice
Group by ID
Having ID = 1

=> result is 1 row with ID = 1 and Money = xxx (OK)

* Case B:
Select ID, Money
from InVoice, Date
Group by ID, Date
Having ID = 1, Date between '2013/11/1' and '2013/11/10'
=> result is many row with ID = 1 and Money = xxx, yyy ...

I would in case B, result display 1 row, ID is 1 and Money is Total

Please help me
Thanks
Posted

If you group by date, it will create an entry for each date. If you just group by id, it will show one value per id, and apply your having clause to the data selected. So, drop the group by date, it's not what you want. You're asking it for a record for each date. Just specify a date range and group by the id and you will be fine.
 
Share this answer
 
In case B: I only want group ID. But when I filter Date then SQL must input Date into Group. I cannot have observe result
 
Share this answer
 
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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