Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

need top 3 game win per customer group per week

$
0
0

HI All

I am stuck with this query and would appreciate all help given. What I am trying to find out is top 3 customergroup ranked as 1,2,3 per day based on game win in descending order  something like this as an example

I have written few codes but neither of them are correct

1st attempt:-

select  * from
(
select Row_number() over (PARTITION by [customer group] order by [customer group],last_day_of_week)as row_num,sum(real_gw)as total,last_day_of_week,[Customer Group]
from 
[data_improvised]
group by 
[Customer Group],LAST_DAY_OF_WEEK
)a
where row_num in (1 ,2, 3)
order by LAST_DAY_OF_WEEK desc

2nd attempt: - 

select 

 top 3 with ties SUM(real_gw),LAST_DAY_OF_WEEK,[Customer Group]
from data_improvised
group  by LAST_DAY_OF_WEEK,[Customer Group]
order by ROW_NUMBER() over(partition by [customer group] order by last_day_of_week desc)

Thanks for your help. Any help would be appreciated

REgards

Farhan JAmil 



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>