Mysql计数(条件)? [英] Mysql count(condition)?

查看:61
本文介绍了Mysql计数(条件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i有一个包含以下字段的表:

id,name,dept,pay

1,John,Sales ,4000

2,Peter,HR,5000




我如何计算每个人中有多少人有一个SQL查询的部门吗?


我发现这个令人惊讶的困难,因为我可以通过使用以下方式总结每个部门的总额

的工资: />
$ query ="

选择总和(if(dept =''HR'',pay,0))为hrpay,......

" ;;


TIA

Hi,
i have a table that has the following fields:
id, name, dept, pay
1, John, Sales, 4000
2, Peter, HR, 5000
etc.

How do i count how many people there are in each dept with an sql query?

I find this surprisingly difficult, given the fact that i can sum the total
pay for each dept by using:
$query="
Select sum(if (dept=''HR'', pay, 0)) as hrpay, ......
";

TIA

推荐答案

query ="

选择总和(if(dept =''HR'',pay,0))为hrpay,......

" ;;


TIA

query="
Select sum(if (dept=''HR'', pay, 0)) as hrpay, ......
";

TIA


" dottty" <做**** @ noemailpls.met>在留言中写道

news:44 *********************** @ news.sunsite.dk ...
"dottty" <do****@noemailpls.met> wrote in message
news:44***********************@news.sunsite.dk...

我有一个包含以下字段的表:
id,name,dept,pay
1,John,Sales,4000
2,Peter,人力资源,5000

我如何计算每个部门有多少人使用SQL查询?

我觉得这非常困难,因为事实上,我可以使用以下方法计算每个部门的
总薪酬:
Hi,
i have a table that has the following fields:
id, name, dept, pay
1, John, Sales, 4000
2, Peter, HR, 5000
etc.

How do i count how many people there are in each dept with an sql query?

I find this surprisingly difficult, given the fact that i can sum the total pay for each dept by using:


query ="
选择总和(if(dept ='') HR'',pay,0))作为hrpay,......
" ;;

TIA
query="
Select sum(if (dept=''HR'', pay, 0)) as hrpay, ......
";

TIA




SELECT Count(dept)AS deptcount

FROM [table]

GROUP BY id



SELECT Count(dept) AS deptcount
FROM [table]
GROUP BY id


这篇关于Mysql计数(条件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆