select
sum(case a when 0 then b else 0 end) as qty1,
sum(case a when 1 then b else 0 end) as qty2,
sum(b) - qty1 - qty2 as qty3 //qty3我是想实现这样的功能,但我知道这样写肯定不对,不知道怎么能实现?
from table1
group by...
sum(case a when 0 then b else 0 end) as qty1,
sum(case a when 1 then b else 0 end) as qty2,
sum(b) - qty1 - qty2 as qty3 //qty3我是想实现这样的功能,但我知道这样写肯定不对,不知道怎么能实现?
from table1
group by...
sum(case a when 0 then b else 0 end) as qty1,
sum(case a when 1 then b else 0 end) as qty2,
sum(b) - sum(case a when 0 then b else 0 end)-sum(case a when 1 then b else 0 end) as qty3
from table1
group by...
等同于
sum(case a when 0 then 0 when 1 then 0 else b end) as qty3
from(
select
sum(case a when 0 then b else 0 end) as qty1,
sum(case a when 1 then b else 0 end) as qty2,
sum(b) as b
from table1
group by..) b
sum(case a when 0 then b else 0 end) as qty1,
sum(case a when 1 then b else 0 end) as qty2,
sum(b) - qty1 - qty2 as qty3 //qty3我是想实现这样的功能,但我知道这样写肯定不对,不知道怎么能实现?
from table1
group by...select
sum(case a when 0 then b else 0 end) as qty1,
sum(case a when 1 then b else 0 end) as qty2,
(sum(b) - sum(case a when 0 then b else 0 end) - sum(case a when 1 then b else 0 end)) as qty3 //qty3我是想实现这样的功能,但我知道这样写肯定不对,不知道怎么能实现?
from table1
group by...