You are here: Re: Help!? Combining SQL Queries? Can it be done?? « MsSQL Server « IT news, forums, messages
Re: Help!? Combining SQL Queries? Can it be done??

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация