sql server - Microsoft SQL-Apply "Where" Clause to Particular Columns -


i trying number of days person has total recording time on amount multiple amounts. right able 1 column of accurate data number of days(i getting days on 60 in of days columns. want return 0 persons not having days particular recording length increment. want number of days increments persons having days recording lengths in increments.

essentially wish put "where" clause column name define column.(i know doesn't work way) best way to tackle problem?

here code:

with cterecordingsbydate (     select      person.firstname,                 person.lastname,                 cast(created date) whole_date,                 sum(length)/60 recordings_sum, --length in seconds            recordings     join        person on recordings.personid=person.id           created between '2013-07-01 00:00:00.000'                          ,     '2013-08-01 00:00:00.000'     group    person.firstname,                  person.lastname,                 cast(created date) )  select      firstname,              lastname,              count(*) daysabove60             count(*) daysabove100             count(*) daysabove140        cterecordingsbydate       recordings_sum >= 60 ,         recordings_sum < 100 group    firstname, lastname order    count(*) desc 

remove clause , use case inside count functions:

count(case when recordings_sum >= 60 , recordings_sum < 100 1 end) daysabove60 count(case when recordings_sum >= 100 , recordings_sum < 140 1 end) daysabove100 count(case when recordings_sum >= 140 1 end) daysabove140 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -