- 方法一,用row_number
分组为1,在组内编号排序。
代码 select row_num(a.num) num,
event_query,
search_num
from
(
select ‘1‘ as num,
event_query,
search_num
from
(
SELECT event_query
,count(1) AS search_num
FROM default.table
WHERE event_day = ‘20150406‘
GROUP BY event_query
SORT BY search_num DESC
LIMIT 100
)a
)aa
2 .方法二,用python
每一行添加一个字段输出
import sys
num=0
for line in sys.stdin:
line = line.strip()
if line!="":
num=num+1
print("%d\t%s") %(num,line)
top100的数据中添加序号字段,推荐方法二,效率高。
时间: 2024-10-17 07:28:12