|
Posted by Ed Murphy on 12/18/06 16:37
isdeveloper@hotmail.com wrote:
> date || user || transaction type || Amount
I hope this table has a primary key, and you just omitted mentioning it
because this particular case doesn't use it.
> I want to get one particular transaction type as a percentage of the
> total transactions : for example, a list of the % amount that Debit
> transactions have occurred for a user for a day, with respect to all
> transactions that the user has done that day, so :
>
> Debits Jim performed on day 1 are 50% of all transactions he performed
> Debits Jim performed on day 2 are 55% of all transactions he performed
[snip]
> Can anyone suggest a way of doing this without the need for these
> temporary tables???
Untested:
select date, user,
coalesce(
sum(case transaction_type when 'debit' then amount else 0 end)
, 0
) / sum(amount) as perc_debit
from the_table
group by date, user
[Back to original message]
|