|
Posted by Ed Murphy on 05/07/07 09:01
estesiquevale@gmail.com wrote:
> I have a table like this:
>
> thing, size, color, type_mov, vary
> 1, s, red, sell, 1
> 1, s, red, buy, 2
> 1, m, green, return, 10
> ....
>
> and the question is how I can see the total number of products by size
> and color having in mind that some type of movement are + and other
> are -.
This should get you on the right track:
select thing, size, color, sum(
case when type_mov in ('buy', 'return') then vary else -vary end
) as total_change
from the_table
group by thing, size, color
Navigation:
[Reply to this message]
|