sql server - How to make Query for that -
i have table structure there have make query in different way
table structure
id unique identifier
code varchar(5) not null
recording_date datetime not null
max_temp numeric(5,2) not null
min_temp numeric(5,2) not null
we have data in table.we have data 2013 year , first 3 months. main thing have return's data in such format like
please me create query such logic.
thanks in advance.
presuming have 1 recording per day
select datepart(m, month_start) + ' ' + datepart(yyyy, month_start) , max_temp_days , case when denominator = 0 0 else (max_temp_days / denominator) * 100 end percent_max_temp_days , min_temp_days , case when denominator = 0 0 else (min_temp_days / denominator) * 100 end percent_max_temp_days ( select dateadd(month, datediff(month, 0, recording_date), 0) month_start , sum(case when max_temp <= 0 1 end) max_temp_days , sum(case when min_temp <= 0 1 end) min_temp_days , count(*) denominator temperaturerecordings recording_date between '2013-01-01' , '2013-03-31' group dateadd(month, datediff(month, 0, recording_date), 0) ) t order month_start
Comments
Post a Comment