Skip to content

Instantly share code, notes, and snippets.

@sethdorris
Created March 22, 2021 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethdorris/87091df16414c94a30398dc3184df683 to your computer and use it in GitHub Desktop.
Save sethdorris/87091df16414c94a30398dc3184df683 to your computer and use it in GitHub Desktop.
WITH cts AS (SELECT COUNT(Id) as UniqueCount, MIN(Triggers.Id) as LowestTriggerId
FROM Triggers
GROUP BY DeviceId, AccelerationPeakMagnitude_G, PeakOverPressure_Psi)
SELECT COUNT(cts.UniqueCount) AS UniqueTriggers FROM cts
WITH cte AS (SELECT MIN(Triggers.Id) as LowestTriggerId
FROM Triggers
GROUP BY DeviceId, AccelerationPeakMagnitude_G, PeakOverPressure_Psi)
SELECT Count(*) FROM (SELECT COUNT(*) AS theCounts FROM cte
left JOIN PressureData ON cte.LowestTriggerId = PressureData.TriggerId
GROUP BY PressureData.TriggerId) AS outercount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment