Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. with clientposition as (
  2. SELECT
  3. customerID
  4. ,MAX(SCORE) as 'SCORE'
  5. --,ROW_NUMBER() OVER ( Order BY MAX(Score) desc ) as 'RNumber'
  6. ,CONVERT(DATE, startdate, 105) as 'date'
  7. FROM
  8. BIA_DEV.bf.interactions
  9. --WHERE
  10. --Startdate > CONVERT(date, GETDATE()-1, 105)
  11. --AND Startdate < CONVERT(date, getdate(), 105)
  12. GROUP BY CustomerId, CONVERT(date, StartDate, 105)
  13. ), totalScore as (
  14. SELECT
  15. CustomerID
  16. ,SUM(SCORE) as TotalMaxScore
  17. ,ROW_NUMBER() OVER (Order By SUM(Score) DESC) as 'ActualRNumber'
  18. from clientposition
  19. GROUP BY CustomerId
  20. ), rowposition as (
  21. SELECT customerid, ActualRNumber from totalScore where CustomerId = 'e84693b7-7763-4e23-8900-1b18bd36e956'
  22. )
  23. SELECT totalScore.CustomerId, Totalscore.TotalMaxScore, TotalScore.ActualRNumber
  24. from totalScore, rowposition
  25. where totalscore.ActualRNumber between rowposition.ActualRNumber - 1 AND rowposition.ActualRNumber + 1
  26. GROUP BY totalScore.CustomerId, totalScore.TotalMaxScore, totalScore.ActualRNumber
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement