# 请问如何作出这样的视图？？？？？？？？？？？？？？？？？？？？

WareID(商品编号) SaleNum(销售数量) isTally(是否结帐)
001 5 1 1:结帐；0：未结
001 3 0

WareID isNum(已经结帐数量) notisNum(未结帐数量)
001 5 3

...全文
17 5 打赏 收藏 转发到动态 举报

5 条回复

pengdali 2003-11-19
• 打赏
• 举报

create view 视图名
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
• 打赏
• 举报

WareID(商品编号) SaleNum(销售数量) isTally(是否结帐)
001 5 1 1:结帐；0：未结
001 3 0

0 否
1 是

zjcxc 元老 2003-11-19
• 打赏
• 举报

create view 视图名
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
txlicenhe 2003-11-19
• 打赏
• 举报

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

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
wzh1215 2003-11-19
• 打赏
• 举报

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

34,499

• 近7日
• 近30日
• 至今