Hey,
So i'm relatively new to using SQL, or at least haven't used it since my college days and therefor can't seem to get something pretty basic to work.
I have ONE table called TRACKING_TRAIN that tracks all activities from one user. Each activity is assigned a code. The table captures the transaction code, the time it was done, and the username of who did the transaction.
I'm trying to pull bits and pieces of this information into 1 table as a means of measuring someones productivity by the number of actions on a certain day.
Example of what I want my table to look like
Name | Action 1 | Action 2 | Action 3 |
------------------------------------------
John | 34 | 2 | 4 |
Sarah | 2 | 2 | 3 |
Because all actions are a different I'm using 3 different queries. The first pulls the user_ID and counts the number of items that were touched using Action 1, grouping it by User_ID. That part works fine. Once I add my additional queries I don't really know how to merge them so I get duplicate results of the name field.
Here's an example of my code:
I'm probably making a pretty dumb mistake, but it's been years since college and I never really paid attention in my SQL class. Be gentle.
So i'm relatively new to using SQL, or at least haven't used it since my college days and therefor can't seem to get something pretty basic to work.
I have ONE table called TRACKING_TRAIN that tracks all activities from one user. Each activity is assigned a code. The table captures the transaction code, the time it was done, and the username of who did the transaction.
I'm trying to pull bits and pieces of this information into 1 table as a means of measuring someones productivity by the number of actions on a certain day.
Example of what I want my table to look like
Name | Action 1 | Action 2 | Action 3 |
------------------------------------------
John | 34 | 2 | 4 |
Sarah | 2 | 2 | 3 |
Because all actions are a different I'm using 3 different queries. The first pulls the user_ID and counts the number of items that were touched using Action 1, grouping it by User_ID. That part works fine. Once I add my additional queries I don't really know how to merge them so I get duplicate results of the name field.
Here's an example of my code:
Code:
SELECT User_ID, count(DISTINCT object_Id) as Action 1, null as Action 2, null as Action 3 FROM TABLE 1 WHERE tran_type = '010' AND tran_code = '004' AND TRUNC(MOD_DATE_TIME) = TRUNC(SYSDATE -6) Group by user_id UNION SELECT User_ID, null as Action 1, count(DISTINCT object_Id) as Action 2, null as Action 3 FROM TABLE 1 WHERE tran_type = '500' AND tran_code = '003' AND TRUNC(MOD_DATE_TIME) = TRUNC(SYSDATE -6) Group by user_id UNION SELECT User_ID, null as Action 1, null as Action 2, count(DISTINCT object_Id) as Action 3 FROM TABLE 1 WHERE tran_type = '100' AND tran_code = '090' AND TRUNC(MOD_DATE_TIME) = TRUNC(SYSDATE -6) Group by user_id
Comment