我现在有张手机库存表,里面存有手机型号PHone_Code,库存状态Status(0为未出库,2为已出库),出库日期OutStorehouseTime,我现在要按机型和日期去统计每天出库的数量。就是要看到每个机型从1号到30号每天的出库数量。SQL语句怎么写啊!高手指点!谢谢!
select OutStorehouseTime,PHone_Code,sum(case when status=2 then 1 else 0 end)
from 库存表
group by OutStorehouseTime,PHone_Code
不知道是不是你想要的
create view _view
as
select *,PHone_Code+Convert(nvarchar(20),OutStorehouseTime,120) as _group
from _table
where Status=2
select
count(*) as 出库数量,
max(PHone_Code) as PHone_Code,
max(OutStorehouseTime) as OutStorehouseTime
from _table group by _group
order by OutStorehouseTime
疑问:库存状态为2,默认都是指出库数量为1??