在计数查询中需要帮助 [英] need help in count query
本文介绍了在计数查询中需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我正在使用下面的查询计数我的表中的礼物数量
Hi all
i am counting the number of present in my table using the below query
select count(present)from attendance
where present='true'
但我希望它是明智的员工计数..
请告诉我该怎么做..
表示它应该显示
Emp_Name当前计数
一个2
b 3
c 0
像这样..
but i want it employee wise counting..
please tell me how to do that..
means it should display
Emp_Name Present Count
a 2
b 3
c 0
like this..
推荐答案
您将需要Group By
子句.
试试:
You would needGroup By
clause.
Try:
SELECT
Emp_Name,
COUNT(Present)
FROM
ATTENDANCE
WHERE
Present = 'true'
GROUP BY
Emp_Name
顺便说一句,建议:您应该将"present"列作为BIT字段而不是字符串.
BTW, a suggestion: you should make ''present'' column as a BIT field instead of a string.
尝试一下
SELECT Emp_Name,
SUM(CASE WHEN present = 'True' THEN 1 ELSE 0 END) AS [Present Count],
SUM(CASE WHEN present = 'False' THEN 1 ELSE 0 END) AS [Absent Count]
from attendance
GROUP BY Emp_Name
尝试以下操作:
Try this:
SELECT
Emp_Name AS Name
,COUNT(present) AS Cnt
FROM tableName
WHERE
present = 'true'
GROUP BY
Emp_Name
ORDER BY
Name;
或
Or
SELECT
Emp_Name,
count(present)
FROM tableName
WHERE
present = 'true'
GROUP BY
Emp_Name
这篇关于在计数查询中需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文