Re: [SQL ] SELECT * FROM x GROUP BY y 語法

作者: cutekid (可愛小孩子)   2017-12-19 11:58:17
select ID,sum(unit * quantity) as count,
case min(
case status
when 'Fail' then 1
when 'Pending' then 2
when 'OK' then 3
end
)
when 1 then 'Fail'
when 2 then 'Pending'
when 3 then 'OK'
end as status
from table
group by ID
※ 引述《DRLai (蘇打)》之銘言:
: 資料庫名稱:MariaDB
: 資料庫版本:10
: 內容/問題描述:
: 資料大致如下
: ID unit quantity status
:
作者: criky (2501-2)   2017-12-19 13:50:00
推一個
作者: DRLai (蘇打)   2017-12-19 21:31:00
原來可以這樣寫,感謝 m(_ _)m

Links booklink

Contact Us: admin [ a t ] ucptt.com