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