Mysql 如何为单个列中的值添加多个条件,并在单独的列中显示结果?

Mysql 如何为单个列中的值添加多个条件,并在单独的列中显示结果?,mysql,sql,Mysql,Sql,我的桌子的结构如下所示 数 地位 123 失败 456 失败 123 成功 789 失败 789 成功 456 成功 123 成功 以下是您可以如何做到这一点: select number , count(*) total , count(case when status = 'fail' then 1 end) fail_count , count(case when status = 'success' then 1 end) success_co

我的桌子的结构如下所示

数 地位 123 失败 456 失败 123 成功 789 失败 789 成功 456 成功 123 成功
以下是您可以如何做到这一点:

select number 
       , count(*) total
       , count(case when status = 'fail' then 1 end) fail_count
       , count(case when status = 'success' then 1 end) success_count
from yourtable
group by number

请避免粘贴截图,请返回文本谢谢,兄弟!它就像一个符咒。你能给我推荐一些详细学习SQL的资料吗。我知道SQL,但我的知识很肤浅。@SyedKamranAhmed不客气,还有很多免费资源,如果你用谷歌搜索,我对任何具体内容都不熟悉