Skip to content

Instantly share code, notes, and snippets.

@luisdelatorre012
Created September 12, 2024 15:41
Show Gist options
  • Save luisdelatorre012/55bcb8fbc60a36a94c919666d8ba6ead to your computer and use it in GitHub Desktop.
Save luisdelatorre012/55bcb8fbc60a36a94c919666d8ba6ead to your computer and use it in GitHub Desktop.
cross apply
SELECT
t.Category,
MIN(j.eventRecordedTime) AS MinEventTime,
MAX(j.eventRecordedTime) AS MaxEventTime,
AVG(j.someNumericValue) AS AvgValue
FROM
t
CROSS APPLY OPENJSON(CAST(CAST(t.message AS varchar(max)) AS nvarchar(max)))
WITH (
eventRecordedTime datetime2 '$.eventRecordedTime',
someNumericValue float '$.someNumericValue'
) AS j
GROUP BY
t.Category
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment