2016-09-26 104 views
-1

我的SQL查詢組中的多個字段數據作爲一個字段

select status,count(id) from table group by status; 

回報以下數據

Resolved- 4 
Closed - 12 
Verified - 3 
New* - 23 
Unconfirmed* - 4 
Needmoreinfo* - 5. 

我希望MySQL返回什麼是

Resolved- 4 
Closed - 12 
Verified - 3 
Found* - 32 

即新的,未確認,Needmoreinfo應計爲'發現'

+0

提供一些示例表數據並準確解釋問題。 – Wanderer

+0

select CASE WHEN status NOT IN('Resolved','Closed','Verified')THEN'FOUND'ELSE status END as derived_status,count(id)from table group by CASE WHEN status NOT IN('Resolved','Closed ','已驗證')然後'找到'ELSE狀態結束; –

回答

1

你的問題是缺少信息來幫助你..但也許你想要這個

SELECT 
CASE WHEN (status NOT IN ('Resolved', 'Closed', 'Verified')) THEN 'Found*' ELSE status END as status, count(id) 
FROM table 
GROUP BY CASE WHEN (status NOT IN ('Resolved', 'Closed', 'Verified')) THEN 'Found*' ELSE status END 
+1

thx ..正是我需要的 – user2095748

0

第一件事情是我們NNED改變烏爾表即增加一個額外科拉姆 LTER TABLE yourtable地址列中找到VARCHAR(50);

UPDATE yourtable SET Found = CONCAT(New,' - ',Unconfirmed,',',Needmoreinfo);

現在您可以編寫選擇查詢

相關問題