Say I have a dataset like this:
MANAGER | USER | NUM1 | NUM2 | NUM3 ---------|--------|--------|--------|------- Bob | Jane | 9 | 88 | 2 Bob | Jane | 34 | 32 | 52 Bob | Jane | 32 | 111 | 9 Bob | Rick | 64 | 1 | 102 Bob | Rick | 12 | 41 | 16 Bob | Rick | 4 | 13 | 20 Bob | Mark | 87 | 1 | 333 Bob | Mark | 342 | 41 | 16 Bob | Mark | 54 | 813 | 6 As you can see the number columns are all different, the manager is always the same, and the user is repeating.
I'd like to to group by user so that only one column per user shows up.
So the final dataset would look like this:
MANAGER | USER | NUM1 | NUM2 | NUM3 ---------|--------|--------|--------|------- Bob | Jane | 9 | 88 | 2 Bob | Rick | 64 | 1 | 102 Bob | Mark | 87 | 1 | 333 I'd like to run something like this:
SELECT MANAGER, USER, NUM1, NUM2, SUM(NUM3) AS NUM3 FROM MYTABLE GROUP BY USER This code will not work since you need to group by all aggregate functions. I don't want to use any aggregate functions on the other columns since they will change the values for NUM1 and NUM2. Is there any way around this? Anyone know what I can do to make this happen?
sum(num3)? Your final dataset just has one row from the original data, without any aggregation, which doesn't seem to match what you've said. Was "one column per user" supposed to be "one row..."? If you want one row, how will you decide which one?