select code ,inqty =sum(case type when 0 then qty else 0 end), outqty=sum(case type when 1 then qty else 0 end) from tablename group by code
Cannot resolve collation conflict for equal to operation. 报这个错误
一楼的语句漏了个条件应该是 select code,sum(qty) inqty,(select sum(qty) outqty from tablename t2 where t1.code=t2.code and t2.type=1) from tablename t1 where type=0 group by code 二楼的语句应该没错
select code ,inqty =sum(case type when 0 then qty else 0 end), outqty=sum(case type when 1 then qty else 0 end) from tablename group by code 应该没问题啊,楼主是什么数据库?
select code ,inqty =sum(case type when 0 then qty else 0 end), outqty=sum(case type when 1 then qty else 0 end) from tablename group by code
outqty=sum(case type when 1 then qty else 0 end)
from tablename group by code
报这个错误
select code,sum(qty) inqty,(select sum(qty) outqty from tablename t2
where t1.code=t2.code and t2.type=1)
from tablename t1
where type=0
group by code 二楼的语句应该没错
outqty=sum(case type when 1 then qty else 0 end)
from tablename group by code
应该没问题啊,楼主是什么数据库?
outqty=sum(case type when 1 then qty else 0 end)
from tablename group by code