Mysql-语法
Mysql-语法
cmyang自定义排序
order by field(role, 'OWNER', 'ADMIN', 'EDIT', 'VIEW'), id desc
提供了一个pid的集合,如何在每个pid中仅查询两条记录,8.0版本后支持
SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY pid ORDER BY id) AS row_num FROM table_name WHERE pid IN ('pid1', 'pid2', 'pid3', ...) ) AS subquery WHERE row_num <= 2;