sql server - How to calculate with date ranges -
ok coding piece - tat - may simple beating head on this.
this returns # of toys each girl
select toys, count(girls), tat table1 (nolock)
i.e.
girl toys tat _____ ______ ___________ kelly 1 0-5 michelle 1 16-30 grace 1 31+ katy 1 6-10 kelly 1 16-30
this returns # of toys in each age range
select tat, count(tat) table1 (nolock)
i.e.
tat ?????? _____ ___________ 0-5 1 6-10 0 11-15 1 16-30 2 31+ 1
the next step need divide 1 (kelly 16-30) # of toys in age range put in (2 16-30) :
1 / 2 = 50.00%
how do that? column ???? stuck at.
thank you! holly
create table #table1 (girl varchar(20), toys int, tat varchar(10)) insert #table1 (girl, toys, tat) values ('kelly',1,'0-5') ,('michelle',1,'16-30') ,('grace',1,'31+') ,('katy',1,'6-10') ,('kelly',1,'16-30') declare @dividend numeric(5,2) = 1 ;with gtcount (select tat, count(*) ctr #table1 group tat ) select tat,ctr, @dividend/ctr percentage gtcount
hope helps...
elmer
Comments
Post a Comment