2010-09-20 80 views
0

我需要显示的当前状态的计数为特定的名称如何编写嵌套查询?

Select count(*) from employees where status='Present'; 

该查询返回了我整个当前计数。我应该怎么做才能获得某个特定名称的地位?

+1

对于你要求在所有答案中的所有评论的问题,你应该开始看到一些SQL教程,先试试这个:http://www.w3schools.com/sql/default.asp - 啊,并保持在介意SQL不是Microsoft SQL,SQL是数据库查询语言! – balexandre 2010-09-20 10:06:09

回答

2

你的意思是?从员工

select status, count(*) 
from employees 
group by status 

或者

select name, count(*) 
from employees 
where status = 'Present' 
group by name 
+0

如果我在数据库中有一个名称为abc的名称,那么我怎样才能得到数字 – sumithra 2010-09-20 09:56:43

+0

只是添加到'WHERE'子句你的名字,就像'WHERE name ='abc'' – balexandre 2010-09-20 10:04:53

-1

SELECT COUNT(1)其中状态= '现在' 的名字

0

组试试这个:

select name, count(*) 
    from employees 
    where name = 'abc' and 
     status = 'Present'; 

分享和享受。