create view aa
as
select WareID,sum(case isTally when 1 then SaleNum else 0 end) as isNum,sum(case isTally when 0 then SaleNum else 0 end) as notisNum from 表 group by WareID
go
as
select WareID,sum(case isTally when 1 then SaleNum else 0 end) as isNum,sum(case isTally when 0 then SaleNum else 0 end) as notisNum from 表 group by WareID
go
as
select WareID,sum(case isTally when 1 then SaleNum else 0 end) as isNum,
sum(case isTally when 0 then SaleNum else 0 end) as notisNum
from 表 group by WareID
go或
create view aa
as
select WareID,sum(SaleNum * isTally) as isNum,
sum(SaleNum * (1-IsTally)) as notisNum
from 表 group by WareID
go
-- SaleNum * 0 = 0 1-1=0 1-0 = 1
as
select wareid
,isNum=sum(case istally when 1 then salenum else 0 end)
,notisNum=sum(case istally when 0 then salenum else 0 end)
from 表
group by wareid
WareID(商品编号) SaleNum(销售数量) isTally(是否结帐)
001 5 1 1:结帐;0:未结
001 3 0再加上 isPresent(是否赠送)
0 否
1 是
如果是赠送的商品我就不想知道他的销售数量了,这个语句该怎么写呀??
谢谢
as
select wareid,sum(case when istally=1 and isPresent=0 then salenum else 0 end) isNum,sum(case istally=0 and isPresent=0 then salenum else 0 end) notisNum from 表 group by wareid
go