2013-01-23 45 views

回答

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

+1簡短的回答 – neeraj

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 
; 
+1

這是比其他答案更便攜,雖然你已經混起來:它應該是'當issue_Status =「不發出'then 1 else 0'。 –

+0

@AndriyM哦射擊..感謝錯過了這..這將工作在像Oracle的RDBMS以及:)其中'Sum(布爾)'不會工作.. – bonCodigo

+0

@AndriyM是的,它是'MySQL'特定的。但是接下來的問題是*首先*標籤'MySQL'而不是'SQL'。 –