运单表中有300万条记录。现在想列出最近2天内,每类货物的最新5条运单
采用了网上的一些查询语句,运行速度慢,1个多小时都没得出结果。
SELECT
a.*
FROM
project_order a
WHERE 1 >
(SELECT
COUNT(*)
FROM
project_order
WHERE uid = a.uid
AND id > a.id)
ORDER BY a.uid
把 create table 命令发一下,另外说明一下使用的数据库版本
select * frmo (
select a.*, row_number() over(partition by 类别 order by 时间 desc) as r_number from project_order where 时间 < ....) temp
where temp.r_number <= 5