gpt4 book ai didi

sql - 使用 UNION 将两个带有 LIMITS 的语句组合起来

转载 作者:IT王子 更新时间:2023-10-29 06:18:54 27 4
gpt4 key购买 nike

有没有办法将这两个语句合二为一而不会出现重复条目​​?

SELECT * FROM Seq where JULIANDAY('2012-05-25 19:02:00')<=JULIANDAY(TimeP) 
order by TimeP limit 50

SELECT * FROM Seq where JULIANDAY('2012-05-29 06:20:50')<=JULIANDAY(TimeI)
order by TimeI limit 50

SQLITE 不支持我的第一个明显尝试(语法错误:Limit 子句应该在 UNION 之后而不是之前):

SELECT * FROM Seq where JULIANDAY('2012-05-25 19:02:00')<=JULIANDAY(TimeP) 
order by TimeP limit 50
UNION
SELECT * FROM Seq where JULIANDAY('2012-05-29 06:20:50')<=JULIANDAY(TimeI)
order by TimeI limit 50

最佳答案

使用子查询并在其中执行限制。

SELECT  *
FROM ( SELECT *
FROM Seq
WHERE JULIANDAY('2012-05-25 19:02:00') <= JULIANDAY(TimeP)
ORDER BY TimeP
LIMIT 50
)
UNION
SELECT *
FROM ( SELECT *
FROM Seq
WHERE JULIANDAY('2012-05-29 06:20:50') <= JULIANDAY(TimeI)
ORDER BY TimeI
LIMIT 50
)

关于sql - 使用 UNION 将两个带有 LIMITS 的语句组合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10812910/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com