akamorse (7/3/2013)
Thanks for reading 😀Im trying to create a view, and im having trouble doing one function. I have a table with the following
ID timestamp value
1, 04/07/2013 00:00:00, 10
1, 04/07/2013 00:30:00, 11
2, 04/07/2013 00:00:00, 11
2, 04/07/2013 00:30:00, 11
I need the following
ID Count value
1, 2, 21
2, 2, 22
I using the below to get my results when the table only has one month range.
SELECT ID, COUNT(TimeStamp) AS Count, SUM(Vale) AS Value
FROM mytable
GROUP BY ID
Where (ID = '1') OR
(ID = '2') OR
But now i need to add multiple months, and im struggling. Any help would be greatly appreciated.
This would be sufficient:
SELECT ID, COUNT(TimeStamp) AS Count, SUM(Vale) AS Value
FROM mytable
GROUP BY ID
There's no need for a WHERE clause. By the way, not a very effective ID if it has duplicates.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP