Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. USE [MyOnlineBandProd]
  2. GO
  3.  
  4. /****** Object: SqlProcedure [dbo].[u_downloadsPerMonth] Script Date: 10/21/2016 1:02:37 PM ******/
  5. SET ANSI_NULLS ON
  6. GO
  7.  
  8. SET QUOTED_IDENTIFIER ON
  9. GO
  10.  
  11. ALTER proc [dbo].[u_downloadsPerMonth]
  12. (@UserId Uniqueidentifier)
  13. AS
  14. SET NOCOUNT ON
  15. select listenMonth, listenYear,downloadsCount from
  16. (
  17. select ROW_NUMBER() OVER
  18. (PARTITION By a.userId order by YEAR([ListenDate]) desc ,MONTH([ListenDate]) desc)
  19. AS RowNum,
  20. MONTH([ListenDate]) as listenMonth,
  21. YEAR([ListenDate]) as listenYear,
  22. a.UserId,
  23. count(downloads) as downloadsCount
  24. FROM [DownloadLog] d
  25. inner join media m
  26. on m.MediaID=d.MediaId
  27. inner join vw_Artist a
  28. on a.UserId=m.UserId
  29. group by MONTH([ListenDate]), YEAR([ListenDate]) , a.UserId
  30. ) as query
  31. where query.RowNum <=12 and
  32. UserId = @UserId
  33. order by listenYear ,listenMonth
  34.  
  35. SET NOCOUNT OFF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement