我的第一次查询,检索date
和hours
来自给定work_details
中给定employee number
的{{1}}。
date
和第二次查询从表格SELECT date,
SEC_TO_TIME( SUM( TIME_TO_SEC( `total_hours` ) ) ) AS total
FROM `work_details`
WHERE employee_id='28'
and date between '2012-02-01'
and '2012-02-29'
GROUP BY DATE ORDER BY DATE
检索date
:
holy_date
我需要以正确的日期顺序组合两个查询的结果。 我尝试了联合操作,但是得到结果。
我该怎么做?
答案 0 :(得分:1)
有几种方法可以达到你想要的效果。
这不是记录在案的方式。但这应该有用。
SELECT date, total
FROM
(
SELECT date, SEC_TO_TIME( SUM( TIME_TO_SEC( `total_hours` ) ) ) AS total
FROM `work_details`
WHERE employee_id='28' AND date BETWEEN '2012-02-01' AND '2012-02-29'
GROUP BY date
UNION ALL
(
SELECT holy_date AS date, NULL AS total
FROM holiday
WHERE holy_date BETWEEN '2012-02-01' AND '2012-02-29'
)
) AS t
GROUP BY date
ORDER BY date