sql - Select multiple COUNTs for every day -


i got table of visitors. visitor has following columns:

id

starttime (date)

purchased (bool)

shipped (bool)

for each day within last 7 days, want select 3 counts of visitors have day starttime:

  • the count of total visitors
  • the count of total visitors purchased = true
  • the count of total visitors shipped = true

ideally returned result be:

day    total    totalpurchased    totalshipped 1      100      67                42 2      82       61                27 etc... 

i used .net linq has proved quite challenge me.

all have come far following:

select count(*) total [dbo].[visitors] day([starttime]) = day(getdate()) 

it selects total of current day fine, feel pretty stuck right it'd nice if point me in right direction.

for last 7 days use query proposed stanislav where clause

   select day([starttime]) theday,            count(*) tot,            sum(case when purchased=true 1 else 0 end) totpurch,                sum(case when shipped=true 1 else 0 end) totship     [dbo].[visitors]     [starttime] between getdate()-7 , getdate()     group day([starttime])  

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -