Q: find employees who worked for more than 2 days I want to find the id's of employees who worked for more than 2 days from the following attendance table:
id   date    status
1  16-04-06    w
1  16-04-07    w
1  16-04-08    w
2  16-04-06   nw
2  16-04-07   nw
2  16-04-07    w

where w means 'worked' and nw means 'not worked'.
I have tried the following:
select id 
from(select a.id as id,count(*) as cou 
     from attendace a 
     where a.status='w' group by a.id) as myalias 
where cou>2;

I am not sure why i need to use myalias. But, if i dont use it, there is an error saying "every derived table must have its own alias".This query gave the desired output. Could you please help me make an efficient query. Thanks in advance

A: Group the tables by id and then filter with count(*)>2   
 Select id from attendance where status = 'w' group by id having count(*) > 2;


A: try this:
select distinct id from attendance where status='w' group by id having count(1) > 2
SQLFiddle

A: Try:
SELECT id
FROM
attendance
WHERE status = 'w'
GROUP BY id
HAVING COUNT(status) > 2

