每当我运行包含LIMIT
和ORDER BY
关键字的查询时,我会得到不一致的结果,具体取决于LIMIT
子句中指定的项目数:
例如,以下查询:
SELECT "people"."name"
FROM "people"
WHERE "people"."type" = 2
ORDER BY score desc, number desc
LIMIT 50
结果给了我这个:
[John, Jack, Amy, Brad, Tom, ...]
(John和Jack的score
和number
属性都有相同的值。事实上Amy,Brad和Tom也是如此。)
现在,当我跑:
SELECT "people"."name"
FROM "people"
WHERE "people"."type" = 2
ORDER BY score desc, number desc
LIMIT 5
我得到以下结果:
[Jack, John, Tom, Amy, Brad]
答案 0 :(得分:4)
当按值的顺序相同时,数据库可以决定下一个排序是什么,并且它可能会在同一查询的多次运行中发生变化。
尝试按
添加二级订单ORDER BY score, name