我有一个类似这样的查询
SELECT
t.category,
tc.product,
tc.sub-product,
count(*) as sales
FROM tg t, ttc tc
WHERE t.value = tc.value
GROUP BY t.category, tc.product, tc.sub-product;
现在在我的查询中,我想获得每个类别的前 10 个产品(按销售额排名第一),对于每个类别,我需要前 5 个子类别(按销售额排名)
您可以假设问题陈述是这样的:
获得每个类别销售额前 10 名的产品,每个产品获得销售额前 5 名的子产品。
- 这里的类别可以是书籍
- 产品可以是哈利波特的书
- 子产品可以是HarryPorter series 5
样本输入数据格式
category |product |subproduct |Sales [count (*)]
abc test1 test11 120
abc test1 test11 100
abc test1 test11 10
abc test1 test11 10
abc test1 test11 10
abc test1 test11 10
abc test1 test12 10
abc test1 test13 8
abc test1 test14 6
abc test1 test15 5
abc test2 test21 80
abc test2 test22 60
abc test3 test31 50
abc test3 test32 40
abc test4 test41 30
abc test4 test42 20
abc test5 test51 10
abc test5 test52 5
abc test6 test61 5
|
|
|
bcd test2 test22 10
xyz test3 test31 5
xyz test3 test32 3
xyz test4 test41 2
输出将是“
top 5 rf for (abc) -> abc,test1(289) abc,test2 (140), abc test3 (90), abc test4(50) , abc test5 (15)
top 5 rfm for (abc,test1) -> test11(260),test12(10),test13(8),test14(6),test15(5) and so on
我的查询失败了,因为结果非常巨大。我正在阅读有关排名等 Oracle 分析函数的信息。有人可以帮助我使用分析函数修改此查询。任何其他方法也可以工作。
我指的是这个http://www.orafaq.com/node/55。但无法为此获得正确的 sql 查询。
任何帮助将不胜感激..我在这方面被困了 2 天:(