sum - SQL script to check a value then if found increment a field by a value of 1 -


im trying write script pull information table called 'bookings', contains column gives length of each booking called 'hours'. values in column shown 1.0 60 minutes, 0.75 45 minutes, 0.5 30 minutes example. script needs count amount of bookings of particular length , return value, example using sum , case statment each...

sum(case when hours = 1 1 else 0 end) '60 mins',  sum(case when hours = 0.75 1 else 0 end) '45 mins',  sum(case when hours = 0.5 1 else 0 end) '30 mins',  sum(case when hours = 0.25 1 else 0 end) '15 mins' 

my problem need record bookings on 60 minutes , split them 1 of these 4 groups, example 1.5 hours need add value of +1 60 minute case statement , +1 count 30 minute case statement value,

the way think of doing create temporary table columns 60, 45, 30 , 15 count values update table +1 if result found, 1.25 update #temptable column(60) +1 , column(15)+1. not sure how this, appreciated.

thanks

simon

have @ sql fiddle. enough started.

select hours        ,100*(hours - round(hours,0,1)) table1 

so code like

sum(case when hours - round(hours,0,1) = 0 1 else 0 end) '60 mins',  sum(case when hours - round(hours,0,1) = 0.75 1 else 0 end) '45 mins',  sum(case when hours - round(hours,0,1) = 0.5 1 else 0 end) '30 mins',  sum(case when hours - round(hours,0,1) = 0.25 1 else 0 end) '15 mins' 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -