'Cannot select the column I am using to group by
I have this query, which is working fantastically but there is one small problem.
What this query is doing is squashing all the dates into their respective month and then getting the average of the values that fall in that month.
SELECT CAST(AVG(GASVBR) as DECIMAL(10,3)) as "Gas", CAST(AVG(OLVBR) as DECIMAL(10, 3)) as "Oil", CAST(AVG(STROVBR) as DECIMAL(10,3)) as "Strom"
FROM TABLENAME
GROUP BY YEAR(PRSD#), MONTH(PRSD#)
I'd like to include the PRSD# (which is the date) alongside these outputted averages.
As I understand it the problem is I cannot just include the PRSD# in the select statement because it would then output every date, not just the months.
So my question is: How could I output the PRSD# alongside the averages to keep the data understandable? :)
Unfortunately
SELECT GROUP BY (YEAR(PRSD#, MONTH(PRSD#)) as "Datum" CAST(AVG(GASVBR) as DECIMAL(10,3)) as "Gas", CAST(AVG(OLVBR) as DECIMAL(10, 3)) as "Oil", CAST(AVG(STROVBR) as DECIMAL(10,3)) as "Strom"
FROM TABLENAME
GROUP BY YEAR(PRSD#), MONTH(PRSD#)
is not working, would greatly appreciate someone pointing me in the right direction :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
