有没有办法让所有记录符合这些条件:
userid = 1 AND (status < 2 OR time > INTERVAL '1 day')
)如果记录少于10条且更多(如果可用):
userid = 1
最多10(最后,time
)?
答案 0 :(得分:0)
无论什么日期,您似乎都想要最后10个。
但这仍然可以让你不到10岁。
SELECT *
FROM your table
WHERE userid = 1 AND status < 2
order by time desc
LIMIT 10
答案 1 :(得分:0)
SELECT * FROM (
SELECT
*
FROM table
WHERE (userid = 1 AND (status < 2 OR time > INTERVAL '1 day'))
ORDER BY time
LIMIT 10) a
UNION SELECT * FROM (
SELECT
*
FROM table
WHERE userid = 1
ORDER BY time
LIMIT 10) b
LIMIT 10;