I have the following data:
SUM_OF_ALL_PUSHES | USER_LOGIN | COMPONENT_NAME | ROW_LST_UPD_TS
-------------------|---------------|-------------------|-------------------------
61 | DOMAIN\abc | Component A | 22/02/12 12:58:26.325 PM
14 | DOMAIN\xyz | Component B | 22/02/12 05:20:52.565 PM
17 | DOMAIN\xyz | Component A | 22/02/12 05:21:58.045 PM
34 | DOMAIN\abc | Component A | 22/02/12 05:44:20.274 PM
38 | DOMAIN\abc | Component A | 22/02/12 06:28:41.465 PM
I’m deriving the the data using the following:
SELECT SUM(Q.SUM_OF_ALL_PUSHES) AS SUM_OF_ALL_PUSHES, Q.USER_LOGIN, Q.COMPONENT_NAME, Q.ROW_LST_UPD_TS FROM( SELECT
SUM(REGEXP_SUBSTR(SUBSTR(EVENT_MSG, INSTR(EVENT_MSG, ' ', 1,1), INSTR(EVENT_MSG, ' ', 1,1)) , '[0-9]+')) AS "SUM_OF_ALL_PUSHES",
USER_LOGIN,
COMPONENT_NAME,
EVENT_MSG,
ROW_LST_UPD_TS
FROM EVENT_MGT.EVENT_LOG
WHERE
ROW_LST_UPD_TS BETWEEN TRUNC(SYSDATE - 1) AND TRUNC(SYSDATE) - 1/86400
AND SUBSTR(EVENT_MSG,1 ,INSTR(EVENT_MSG, 'd', 1,1)) = 'Received'
GROUP BY
USER_LOGIN,
COMPONENT_NAME,
EVENT_MSG,
ROW_LST_UPD_TS) Q
GROUP BY COMPONENT_NAME, USER_LOGIN, ROW_LST_UPD_TS
ORDER BY ROW_LST_UPD_TS ASC
The issue is that I need to sum the numbers for each user by component. So in the results set above, I need to aggregate columns 1, 4 and 5 and add up the values for SUM_OF_ALL_PUSHES since the records each have user abc, and Component A.
So in summary, I need to remove the data duplication in the other columns, and sum the values in the first column based on user and component. So the result set should look like this:
SUM_OF_ALL_PUSHES | USER_LOGIN | COMPONENT_NAME | ROW_LST_UPD_TS
-------------------|---------------|-------------------|-------------------------
133 | DOMAIN\abc | Component A | 22/02/12 12:58:26.325 PM
14 | DOMAIN\xyz | Component B | 22/02/12 05:20:52.565 PM
17 | DOMAIN\xyz | Component A | 22/02/12 05:21:58.045 PM
Please help.
Sounds like you don’t want to group by the timestamp, but instead apply an aggregate function (I’m guessing
MAX) to it.