Aggregate Function in Grafana MS SQL

Hi Guys,
Long time listener, first time caller … :slight_smile: I’ve been using Grafana for a while with Cloudwatch and PRTG and I’ve been lazy in getting all my data points in little dropdowns. However I’ve recently been pulling data from MS SQL Server.

What I would LIKE to do … is this …

SELECT Count(ReleaseTypeValue) as Metric FROM BAGgateManager.dbo.BPUBagRelease join BAGgateManager.dbo.BPUUnit on (BAGgateManager.dbo.BPUUnit.BPUId = BAGgateManager.dbo.BPUBagRelease.BPUId) where AirportCode = ‘AKL’

and it works great in table mode to display totals, but in order to display in time base, I need a time variable (which I have) but that means I can’t use a SQL aggregate function (eg: count)

SELECT LogTimeLocal as time, count(ReleaseTypeValue) as value FROM BAGgateManager.dbo.BPUBagRelease join BAGgateManager.dbo.BPUUnit on (BAGgateManager.dbo.BPUUnit.BPUId = BAGgateManager.dbo.BPUBagRelease.BPUId) where $__timeFilter(LogTimeLocal) and AirportCode = ‘AKL’

Grafana seems to expect me to have a result set called ‘time’ but that means I can’t use count() unless I group, and if I group by, Grafana doesn’t want to know about it.

Any suggestions gratefully accepted

I don’t understand your tables very well, could you show the creation codes?