0

我必须从下表中找到总库存和可用库存。表结构:

[Inventoryid] [inventory Type ] [issue status]
1              Mobile            Issued
2              Tablet            Not Issued
3              Mobile            Issued
4              Tablet            Not Issued

所需的出口是

[Inventory Type] [Total Inventory]  [Available Inventory]
Mobile            2                  0
Tablet            2                  2

请给我同样的查询。

4

2 回答 2

4
SELECT  inventoryType,
        COUNT(*) totalInventory,
        SUM(issuestatus = 'not issued') available
FROM    tableName
GROUP   BY inventoryType
于 2013-01-23T09:20:30.010 回答
1
select inventory_type , count(*), sum(case when issue_Status = 'not issued' then 1
else 0 end) as status
From yourtable
group by inventory_type
;
于 2013-01-23T09:22:05.563 回答