Hi All,
I have a MSSQL query that is working in SQL Server Mgmt Studio, but isn’t translating well into Grafana. Certainly because I am missing something.
What am I trying to do:
Get a count of events per day into Grafana as a Line Graph formatted as a Table.
The data is from MSSQL and a column that is formatted as Datetime i.e. “2019-12-02 04:32:38.220”.
I see that the time stamp causes to count to be 1 event per that exact timestamp, thus I tried to use Cast. Which worked in SQL:
2020-07-02 2
2020-07-05 3
2020-07-06 4
2020-07-07 5
2020-07-08 6
However, I get an error in Grafana. Does Grafana not interpret Cast the same way?
Error: mssql: Column ‘Decommissions.dbo.DecommissionEvents.ReqDate’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
I am rather new to SQL and Grafana.
SELECT
$__timeGroup(ReqDate, ‘1d’) as time,
CAST(ReqDate as Date) as Date,
Count (ReqDate) as EventsPerDay
FROM [Decommissions].[dbo].[DecommissionEvents]
Where ReqDate >= DATEADD(day,-7, GETDATE())
Group by
CAST (ReqDate as date)
Any suggestions are greatly appreciated.
Thanks.