sqlmysqlsumsap-ase

Unable to Make SUM Operations SQL


I need your help, I have the following Query in SQL (SAP ASE):

SELECT
  DC.DIM_DATE.DATE_ID,
  DC.DIM_TIME.HOUR_ID,
  DC.DIM_E_RAN_UCELL.RBS_ID,
  DC.DIM_E_RAN_UCELL.UCELL_ID,
  (SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestDchPsIntRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumFachPsIntRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestPsHsAdchRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestPsEulRabEstablish))/720 AS 'WCDMA_DATA_ERLANG'
FROM
  DC.DIM_DATE,
  DC.DIM_TIME,
  DC.DIM_E_RAN_UCELL,
  DC.DC_E_RAN_UCELL_RAW
WHERE
  (DC.DC_E_RAN_UCELL_RAW.HOUR_ID=DC.DIM_TIME.HOUR_ID and DC.DC_E_RAN_UCELL_RAW.MIN_ID=DC.DIM_TIME.MIN_ID)
  AND  (DC.DC_E_RAN_UCELL_RAW.DATE_ID=DC.DIM_DATE.DATE_ID)
  AND  (DC.DC_E_RAN_UCELL_RAW.OSS_ID=DC.DIM_E_RAN_UCELL.OSS_ID)
  AND  (DC.DC_E_RAN_UCELL_RAW.RNC=DC.DIM_E_RAN_UCELL.RNC_ID)
  AND  (DC.DC_E_RAN_UCELL_RAW.UtranCell=DC.DIM_E_RAN_UCELL.UCELL_ID)
  AND  
  (
   DC.DIM_DATE.DATE_ID  IN  ('2017-08-02')
   AND
   DC.DIM_E_RAN_UCELL.RBS_ID  IN ('DN1U0441')
  )
GROUP BY
  DC.DIM_DATE.DATE_ID,
  DC.DIM_TIME.HOUR_ID,
  DC.DIM_E_RAN_UCELL.RBS_ID,
  DC.DIM_E_RAN_UCELL.UCELL_ID;

The Output is this:

    DATE_ID HOUR_ID RBS_ID  UCELL_ID    WCDMA_DATA_ERLANG
8/2/2017    0   DN1U0441    DN1U0441A0  0.0222
8/2/2017    0   DN1U0441    DN1U0441A1  0.0138
8/2/2017    0   DN1U0441    DN1U0441B0  0
8/2/2017    0   DN1U0441    DN1U0441B1  0
8/2/2017    0   DN1U0441    DN1U0441C0  0
8/2/2017    0   DN1U0441    DN1U0441C1  0.0472
8/2/2017    1   DN1U0441    DN1U0441A0  0.0555
8/2/2017    1   DN1U0441    DN1U0441A1  0.0166
8/2/2017    1   DN1U0441    DN1U0441B0  0
8/2/2017    1   DN1U0441    DN1U0441B1  0

I'm trying to have all the data from the result in the temporary column WCDMA_DATA_ERLANG in a only row like some TOTAL, but I cant do it, help me please:

Something like that:

DATE_ID HOUR_ID RBS_ID  UCELL_ID    WCDMA_DATA_ERLANG     TOTAL
8/2/2017    0   DN1U0441    DN1U0441A0  0.0222            0.2795
8/2/2017    0   DN1U0441    DN1U0441A1  0.0138
8/2/2017    0   DN1U0441    DN1U0441B0  0
8/2/2017    0   DN1U0441    DN1U0441B1  0
8/2/2017    0   DN1U0441    DN1U0441C0  0
8/2/2017    0   DN1U0441    DN1U0441C1  0.0472
8/2/2017    1   DN1U0441    DN1U0441A0  0.0555
8/2/2017    1   DN1U0441    DN1U0441A1  0.0166
8/2/2017    1   DN1U0441    DN1U0441B0  0
8/2/2017    1   DN1U0441    DN1U0441B1  0

Solution

  • Try selecting from your entire select statement again.

    select DATE_ID, HOUR_ID, RBS_ID, UCELL_ID, WCDMA_DATA_ERLANG, sum(WCDMA_DATA_ERLANG) as total
    from(
    SELECT
      DC.DIM_DATE.DATE_ID,
      DC.DIM_TIME.HOUR_ID,
      DC.DIM_E_RAN_UCELL.RBS_ID,
      DC.DIM_E_RAN_UCELL.UCELL_ID,
      (SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestDchPsIntRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumFachPsIntRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestPsHsAdchRabEstablish)+SUM(DC.DC_E_RAN_UCELL_RAW.pmSumBestPsEulRabEstablish))/720 AS 'WCDMA_DATA_ERLANG'
    FROM
      DC.DIM_DATE,
      DC.DIM_TIME,
      DC.DIM_E_RAN_UCELL,
      DC.DC_E_RAN_UCELL_RAW
    WHERE
      (DC.DC_E_RAN_UCELL_RAW.HOUR_ID=DC.DIM_TIME.HOUR_ID and DC.DC_E_RAN_UCELL_RAW.MIN_ID=DC.DIM_TIME.MIN_ID)
      AND  (DC.DC_E_RAN_UCELL_RAW.DATE_ID=DC.DIM_DATE.DATE_ID)
      AND  (DC.DC_E_RAN_UCELL_RAW.OSS_ID=DC.DIM_E_RAN_UCELL.OSS_ID)
      AND  (DC.DC_E_RAN_UCELL_RAW.RNC=DC.DIM_E_RAN_UCELL.RNC_ID)
      AND  (DC.DC_E_RAN_UCELL_RAW.UtranCell=DC.DIM_E_RAN_UCELL.UCELL_ID)
      AND  
      (
       DC.DIM_DATE.DATE_ID  IN  ('2017-08-02')
       AND
       DC.DIM_E_RAN_UCELL.RBS_ID  IN ('DN1U0441')
      )
    GROUP BY
      DC.DIM_DATE.DATE_ID,
      DC.DIM_TIME.HOUR_ID,
      DC.DIM_E_RAN_UCELL.RBS_ID,
      DC.DIM_E_RAN_UCELL.UCELL_ID)
    group by DATE_ID, HOUR_ID, RBS_ID, UCELL_ID, WCDMA_DATA_ERLANG