date hour trx rnk
18/03/2018 0 1 24
18/03/2018 1 2 23
18/03/2018 2 3 22
18/03/2018 3 4 21
18/03/2018 4 5 20
18/03/2018 5 6 19
18/03/2018 6 7 18
18/03/2018 7 8 17
18/03/2018 8 9 16
18/03/2018 9 10 15
18/03/2018 10 11 14
18/03/2018 11 12 13
18/03/2018 12 13 12
18/03/2018 13 14 11
18/03/2018 14 15 10
18/03/2018 15 16 9
18/03/2018 16 17 8
18/03/2018 17 18 7
18/03/2018 18 19 6
18/03/2018 19 20 5
18/03/2018 20 21 4
18/03/2018 21 22 3
18/03/2018 22 23 2
18/03/2018 23 24 1
17/03/2018 0 1 24
17/03/2018 1 2 23
17/03/2018 2 3 22
17/03/2018 3 4 21
17/03/2018 4 5 20
17/03/2018 5 6 19
17/03/2018 6 7 18
17/03/2018 7 8 17
17/03/2018 8 9 16
17/03/2018 9 10 15
17/03/2018 10 11 14
17/03/2018 11 12 13
17/03/2018 12 13 12
17/03/2018 13 14 11
17/03/2018 14 15 10
17/03/2018 15 16 9
17/03/2018 16 17 8
17/03/2018 17 18 7
17/03/2018 18 19 6
17/03/2018 19 20 5
17/03/2018 20 21 4
17/03/2018 21 22 3
17/03/2018 22 23 2
17/03/2018 23 24 1
这是我的代码
select a.date, a.hour, trx, rank() over (order by a.trx) as rnk from(
select date,hour, count(*) as trx from smy_tb
group by date, hour
)a
limit 100;
问题是: 1.使用相同的trx值重复排名值 2.等级值继续到下一个日期(应按日期和小时分组,因此每个日期只返回24等级值)
需要建议, 谢谢
答案 0 :(得分:1)
您应该partition by
日期列并使用特定的排序。
rank() over (partition by a.date order by a.hour desc)
答案 1 :(得分:0)
由@BKS解释
这是已解决的代码
select a.date, a.hour, trx, row_number() over (partition by a.date order by a.trx desc) as rnk from(
select date,hour, count(*) as trx from smy_tb
group by date, hour
)a
limit 100;