D
D
Djasar2021-03-30 12:23:23
Oracle
Djasar, 2021-03-30 12:23:23

GROUP BY doesn't work, where is the error?

I make a selection from the tables, but the result is not correct. though grouping use.

SELECT  
 /*+ PARALLEL(2) */
   s.ID SID
  ,t.TIME STIME
  ,s.NAME  SNAME
  ,MAX(t.M8_SUM) M8
  ,MAX(t.TRAFF_SUM) TRAFF
  ,MAX(t.PMAC_SUM) PMAC
   from 
        (Select * from (SELECT id,null PMAC_SUM,null TRAFF_SUM, M8_SUM , TIME  FROM TOK.N4444
                       union 
                       SELECT id,null PMAC_SUM,null TRAFF_SUM, M8_SUM , TIME  FROM TOK.N5555)
        UNION 
                      (SELECT id,null PMAC_SUM, TRAFF_SUM ,null M8_SUM, TIME  FROM TOK.H6666 
                       union 
                       SELECT id,null PMAC_SUM, TRAFF_SUM, null M8_SUM , TIME  FROM TOK.H7777)
        UNION 
                      (SELECT id, PMAC_SUM,null TRAFF_SUM ,null M8_SUM, TIME  FROM TOK.E8888 
                       union 
                       SELECT id, PMAC_SUM,null TRAFF_SUM, null M8_SUM , TIME  FROM TOK.E9999))t
      
        LEFT JOIN    (Select ID,NAME from TOK2.ORIGINAL) s ON   s.ID = t.ID  where s.ID is not null and 
        t.TIME = to_timestamp ('2021-01-25' ,'RRRR-MM-DD') and s.ID like '842145'
        group by s.ID,t.TIME,s.NAME,t.M8_SUM ,t.TRAFF_SUM,t.PMAC_SUM

6062eee08e5e7682981485.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-03-30
@Djasar

Change grouping to:

-- group by s.ID,t.TIME,s.NAME,t.M8_SUM ,t.TRAFF_SUM,t.PMAC_SUM
GROUP BY s.ID, t.TIME, s.NAME

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question