Let's say I have a table like this:
Code:
create table table_name (
transaction_id int,
user_id int,
name varchar
)
In reality this is a transactions table joined with a users table. It is important to note that my users table has some distinct users with the same name.
We do a summary report with something like
Code:
select case(grouping(user_id) when 0 then user_id when 1 then 'total' end) as user_id, count(transaction_id) as no_transactions
from table_name
group by user_id
with rollup
This produces a table like
Code:
user_id no_transactions
1 20
2 30
3 10
total 60
I would very much like to see a table like
Code:
user_id no_transactions
Alice 20
Bob 30
Alice 10
total 60
If I group by name instead of id, then the two Alices get combined into one. If I group by both name and id, then I get a summary row for every name, which I do not want. Is it possible?
Thanks