gpt4 book ai didi

mysql - 从结果集中选择 TOP 1

转载 作者:IT老高 更新时间:2023-10-29 00:18:48 25 4
gpt4 key购买 nike

我想检索使用 Union 连接的查询结果集的前 1 个值

SELECT TOP 1 * FROM
(
SELECT paused_time as end_time
FROM production_time
WHERE created_time = curdate()
UNION
SELECT resumed_time as end_time
FROM pause_timer
WHERE created_time = curdate()
UNION
SELECT end_time as end_time
FROM timer_idle
WHERE created_time = curdate()
) as end_time
ORDER BY end_time DESC

却得不到预期的结果。

最佳答案

据我所知,MySQL 中没有TOP 关键字。你需要的是Limit:

SELECT * FROM
(
SELECT paused_time as end_time FROM production_time WHERE created_time = curdate()
UNION
SELECT resumed_time as end_time FROM pause_timer WHERE created_time = curdate()
UNION
SELECT end_time as end_time FROM timer_idle WHERE created_time = curdate()
) as end_time
ORDER BY end_time DESC
LIMIT 1

关于mysql - 从结果集中选择 TOP 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31583953/

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