SQL Pivot query
The PIVOT is the most difficult query to construct (with notepad), if you ask me.
SELECT Datum, [TW-D], [TW-S], [WP-D], [WP-S], [BL-D], [BL-S]
FROM
(SELECT TOP (100) PERCENT DatumMin AS Datum, Item, ValueMin, ValueMax, ValueAvg
FROM dbo.History
WHERE (Item LIKE 'TW-%') OR
(Item LIKE 'WP-%') OR
(Item LIKE 'BL-%')
)
AS Source
PIVOT
(
Max(Valuemax)
FOR
[Item] IN ( [TW-D],[TW-S],[WP-D],[WP-S],[BL-D],[BL-S])
) AS Pivot
ORDER BY Datum DESC
This is just a starter, I’ll explain it later. Just getting it online.


Geef een reactie