我有以下查詢找到軍銜發現排名有兩列甲骨文
SELECT a.appName,RANK() OVER (PARTITION BY a.appName, b.depName ORDER BY a.appName)
as RANK,b.depName,Count(distinct a.userName) as visitors FROM tbl_app_webstats a
inner join tbl_users b on b.userName = a.userName
where a.date_time between '01-JUN-12' and '20-JUN-14' and a.appName like '%'
group by a.appName,b.depName order by a.appName;
,但它給我不正確的結果
appName RANK depName visitors
app1 1 dep1 1
app1 1 dep2 1
app1 1 dep3 2
app2 1 dep1 3
app2 1 dep2 1
app2 1 dep3 5
app3 1 dep2 2
app3 1 dep5 8
app4 1 dep1 2
app4 1 dep5 13
app5 1 dep5 2
結果sholuld是這樣
appName RANK depName visitors
app1 1 dep1 1
app1 2 dep2 1
app1 3 dep3 2
app2 1 dep1 3
app2 2 dep2 1
app2 3 dep3 5
app3 1 dep2 2
app3 2 dep5 8
app4 1 dep1 2
app4 2 dep5 13
app5 1 dep5 2
任何想法這裏可能是錯的?
得益於它的工作是什麼,如果我想找出每個應用排名前10位的部門 – Haider
@Haider:推薦編輯獲得前10名 –