0

我的第一个查询,从给定的给定中检索datehours工作。work_detailsemployee numberdate

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

以及从表中检索的第二个查询dateholy_date

SELECT holy_date
from holiday
where holy_date between '2012-02-01' and '2012-02-29'

我需要以正确的日期顺序组合两个查询的结果。我尝试了联合操作,但没有得到结果。

我该怎么做?

4

1 回答 1

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
于 2012-06-25T14:11:54.283 回答