Grafana - Bar Chart with Multiple Series | How To Tutorial Example

Опубликовано: 20 Октябрь 2024
на канале: CodeCowboyOrg
41,158
226

How to Create a Grafana Bar Chart with Multiple Series Example using SQL Server Database. The Database used here is AdventureWorks downloadable here
https://docs.microsoft.com/en-us/sql/...

SELECT TOP 10 * FROM Sales.SalesOrderDetail

SELECT
DATEPART(Year, ModifiedDate) AS [Year],
DATEPART(Month, ModifiedDate) AS [Month],
COUNT(ModifiedDate) AS Total
FROM Sales.SalesOrderDetail
GROUP BY DATEPART(Year, ModifiedDate) , DATEPART(Month, ModifiedDate)
ORDER BY DATEPART(Year, ModifiedDate) ASC , DATEPART(Month, ModifiedDate) ASC


SELECT [Month] AS [Month],[2011], [2012], [2013], [2014]
FROM
(
SELECT
DATEPART(Year, ModifiedDate) AS [Year],
STR(DATEPART(Month, ModifiedDate)) AS [Month]
FROM Sales.SalesOrderDetail a
) AS SourceTable
PIVOT
(
COUNT(Year)
FOR [Year] IN ([2011], [2012], [2013], [2014])
) AS PivotTable
ORDER BY Month