Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with clientposition as (
- SELECT
- customerID
- ,MAX(SCORE) as 'SCORE'
- --,ROW_NUMBER() OVER ( Order BY MAX(Score) desc ) as 'RNumber'
- ,CONVERT(DATE, startdate, 105) as 'date'
- FROM
- BIA_DEV.bf.interactions
- --WHERE
- --Startdate > CONVERT(date, GETDATE()-1, 105)
- --AND Startdate < CONVERT(date, getdate(), 105)
- GROUP BY CustomerId, CONVERT(date, StartDate, 105)
- ), totalScore as (
- SELECT
- CustomerID
- ,SUM(SCORE) as TotalMaxScore
- ,ROW_NUMBER() OVER (Order By SUM(Score) DESC) as 'ActualRNumber'
- from clientposition
- GROUP BY CustomerId
- ), rowposition as (
- SELECT customerid, ActualRNumber from totalScore where CustomerId = 'e84693b7-7763-4e23-8900-1b18bd36e956'
- )
- SELECT totalScore.CustomerId, Totalscore.TotalMaxScore, TotalScore.ActualRNumber
- from totalScore, rowposition
- where totalscore.ActualRNumber between rowposition.ActualRNumber - 1 AND rowposition.ActualRNumber + 1
- GROUP BY totalScore.CustomerId, totalScore.TotalMaxScore, totalScore.ActualRNumber
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement