【发布时间】:2020-03-01 09:27:58
【问题描述】:
我知道(来自:SQL query for pagination with multiple columns; understand OR operator)以下 Postgres 语法中的 WHERE 子句
SELECT
"id",
"score"
FROM
"players"
WHERE
"score" > '11266' OR ( "score" = '11266' AND "id" > '4482' )
ORDER BY
"score" ASC,
"id" ASC
LIMIT 3
是以下的长形式:
where (score, id) > (11266, 4482)
但是如果我有下面的查询呢?
SELECT
"id",
"score"
FROM
"players"
WHERE
(
( ( "created_at" ) < '2020-02-27 08:57:36.774147+00' ) -- note the "<"
OR ( ( ( "created_at" ) = '2020-02-27 08:57:36.774147+00' ) AND ( ( "score" ) > 11266 ) )
OR ( ( ( "created_at" ) = '2020-02-27 08:57:36.774147+00' ) AND ( ( "score" ) = 11266 ) AND ( ( "id" ) > 4482 ) )
)
ORDER BY
"created_at" DESC,
"score",
"id"
LIMIT 3
你能告诉我一般如何处理这种查询吗?
【问题讨论】:
标签: sql database postgresql performance sorting