Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. [dbo].[ProductTT] (ID int , Product Varchar(50) , Time Int)
  2.  
  3. 1 XX 0030
  4. 2 UY 0354
  5. 3 YY 0517
  6. 4 ZZ 0712
  7. 5 WW 0415
  8. 6 GG 1112
  9. 7 MM 1030
  10. 8 HH 0913
  11.  
  12. With CTE
  13. AS (select ID,
  14. product,
  15. [time],
  16. Case
  17. When left(time,2)>=00 and left(time,2)< 03 then 'group1'
  18. when left(time,2)>=03 and left(time,2)< 06 then 'group2'
  19. when left(time,2)>=06 and left(time,2)< 09 then 'group3'
  20. when left(time,2)>=09 and left(time,2)<=12 then 'group4' End AS groupID
  21. from [dbo].[ProductTT]
  22.  
  23. )
  24. select groupid,count(*) as recordcount
  25. from cte
  26. group by groupid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement