Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

group by 15 minute interval sql server

SELECT   DATEADD(MINUTE, DATEDIFF(MINUTE, '2000', aa.[date]) / 10 * 10, '2000')
                                                             AS [date_truncated],
         COUNT(*) AS [records_in_interval],
         AVG(aa.[value]) AS [average_value]
FROM     [friib].[dbo].[archive_analog] AS aa
-- WHERE aa.[date] > '1900-01-01'
GROUP BY DATEADD(MINUTE, DATEDIFF(MINUTE, '2000', aa.[date]) / 10 * 10, '2000')
ORDER BY [date_truncated]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #group #minute #interval #sql #server
ADD COMMENT
Topic
Name
3+8 =