![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 -. |
#3
| |||
| |||
|
|
estesiquevale (AT) gmail (DOT) 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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |