gpt4 book ai didi

mysql - 如何将两个查询结果显示为一个

转载 作者:行者123 更新时间:2023-11-29 02:45:31 25 4
gpt4 key购买 nike

我有两个 mysql 查询,它们为相同类型的列提供不同的数据。现在我想将这两个结果合并为一个。以下是我的查询。

查询-1:

SELECT cl.cand_corp_id as corpId, cl.shortlisted_timestamp as updatedDate, count(1) as activityCount
FROM candidates_log cl
where cl.shortlisted_timestamp > DATE_ADD(current_date(), INTERVAL -30 DAY)
group by cl.cand_corp_id
order by cl.shortlisted_timestamp desc

结果 1: enter image description here

查询 2:

select j.corp_id as corpId, j.created_at as updatedDate, count(1) as activityCount
from jobs j
where j.created_at > DATE_ADD(current_date(), INTERVAL -30 DAY)
group by j.corp_id
order by activityCount, j.created_at desc limit 5

结果 2; enter image description here

我怎样才能得到这两个结果集的并集的最终结果。

最佳答案

您可以尝试 UNION ALL(应该在这两个查询之间)。如果列/数据的类型相同,它应该可以工作。

SELECT cl.cand_corp_id as corpId, cl.shortlisted_timestamp as updatedDate, count(1) as activityCount
FROM candidates_log cl
WHERE cl.shortlisted_timestamp > DATE_ADD(current_date(), INTERVAL -30 DAY)
GROUP BY cl.cand_corp_id
ORDER BY cl.shortlisted_timestamp desc
UNION ALL
SELECT j.corp_id as corpId, j.created_at as updatedDate, count(1) as activityCount
FROM jobs j
WHERE j.created_at > DATE_ADD(current_date(), INTERVAL -30 DAY)
GROUP BY j.corp_id
ORDER BY activityCount, j.created_at desc limit 5;

关于mysql - 如何将两个查询结果显示为一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42897907/

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