2017-02-09 153 views
-2

我想只得到1行的日期:集團通過或添加

select Datum, ZONE_2, 0 as SEEFRACHT 

     from (

      select to_char(arch_p.ANKUEND_TERMIN,'dd.mm.yy') as Datum, Count (*) as ZONE_2 
      from ARCH_PACKSTUECK arch_p 
      where (arch_p.lbr_auf_nr like '%02') 
      group by to_char(arch_p.ANKUEND_TERMIN,'dd.mm.yy') 

      union all 

      select to_char(ANKUEND_TERMIN,'dd.mm.yy') as Datum, Count (*) as ZONE_2 
      from PACKSTUECK p 
      where(p.lbr_auf_nr like '%02') 
      group by to_char(p.ANKUEND_TERMIN,'dd.mm.yy') 

      order by Datum   
      ) 
DATUM |ZONE_2|SEEFRACHT 
01.02.17 5 0 
01.02.17 588 0 
02.02.17 52 0 
02.02.17 484 0 

enter image description here

+1

請訪問http:/ /meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems- to-me-to-a-very-simple-sql-query – Strawberry

回答

1

試試這個

select Datum, sum(ZONE_2) as ZONE_2, 0 as SEEFRACHT 
     from (

      select to_char(arch_p.ANKUEND_TERMIN,'dd.mm.yy') as Datum, Count (*) as ZONE_2 
      from ARCH_PACKSTUECK arch_p 
      where (arch_p.lbr_auf_nr like '%02') 
      group by to_char(arch_p.ANKUEND_TERMIN,'dd.mm.yy') 

      union all 

      select to_char(ANKUEND_TERMIN,'dd.mm.yy') as Datum, Count (*) as ZONE_2 
      from PACKSTUECK p 
      where(p.lbr_auf_nr like '%02') 
      group by to_char(p.ANKUEND_TERMIN,'dd.mm.yy') 

      ) as t 
     group by Datum   
     order by Datum   
+0

很好,謝謝:-) – Emjot