How can I combine 2 queries?

前端 未结 3 1186
猫巷女王i
猫巷女王i 2021-01-29 08:34

I have these below queries in fastreport. I would like to combine them together into one query. How can I do this ?

SELECT 
    EAMEMID, COUNT (EAMATTNSTATUS)/2          


        
3条回答
  •  滥情空心
    2021-01-29 09:23

    You can use union same way:

    SELECT * FROM
    (
      SELECT 
        1 AS NUMQUERY, EAMEMID, COUNT(EAMATTNSTATUS)/2 as ABSENTDAYS
      FROM 
        viewDAILYSUM  
      WHERE 
        (EAMEMID = :EAMEMID) 
        AND (EAMDATE BETWEEN :FDate AND :TDate)
        AND (EAMATTNSTATUS IN (7, 8))           
      GROUP BY 
        EAMEMID
    
      UNION
    
      SELECT 
        2, EAMEMID, COUNT(DISTINCT EAMDATE)        
      FROM 
        viewDAILYSUM  
      WHERE 
        (EAMEMID = :EAMEMID) 
        AND (EAMDATE BETWEEN :FDate AND :TDate)
        AND (EAMATTNSTATUS IN (6))
      GROUP BY 
        EAMEMID
    )
    ORDER BY NUMQUERY, EAMEMID
    

提交回复
热议问题