【发布时间】:2017-08-11 09:28:54
【问题描述】:
我有两个 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
查询-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
如何通过这两个结果集的并集得到最终结果。
【问题讨论】:
-
显示你需要的结果。如果两个结果集中都存在同一对
corpId, updatedDate,您需要对activityCount求和还是什么?