Skip to content

Instantly share code, notes, and snippets.

@siennathesane
Created December 10, 2019 21:11
Show Gist options
  • Save siennathesane/20e7c0255be27b9cd05e7d567a63c7c5 to your computer and use it in GitHub Desktop.
Save siennathesane/20e7c0255be27b9cd05e7d567a63c7c5 to your computer and use it in GitHub Desktop.
use timeseriesdb
declare @now datetime2 = sysutcdatetime()
select avg(count) from (select count(*) from (select COLUMN_NAME
from (select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_SCHEMA = 'default' and TABLE_NAME = 'timeseriestable'
)
where COLUMN_NAME = '%pattern')
where time_primary_key <= @now
and time_primary_key >= dateadd(minute , -30, @now)
order by time_primary_key) as count;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment