如果一个查询没有提取数据,则Mysql查询无法使用join

时间:2013-01-23 09:17:51

标签: mysql sql

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

[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

请给我相同的查询。

2 个答案:

答案 0 :(得分:4)

SELECT  inventoryType,
        COUNT(*) totalInventory,
        SUM(issuestatus = 'not issued') available
FROM    tableName
GROUP   BY inventoryType

答案 1 :(得分: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
;