Sabyasachi Gupta Sabyasachi Gupta - 3 months ago 16
MySQL Question

how to select records which pertains to the current month

I have a table (attendance) which stores attendance data for employees.Every day , the admin logs in into his system , selects the date(on that date) and marks an employee as present or absent for that date . These records are stored in the attendance table .

I want to retrieve all records for a particular

EmpId
for the current month where attendance is marked either
present / absent
.

The column names of attendance table are :

1.EmpId - numeric
2.date:date type
3.status(either present/absent)-varchar



  • I want to write a query for retrieving all records for a particular
    EmpId
    (say 1) for the current month where
    status="present"

  • I want to write another query for retrieving all records for a particular
    EmpId
    (say 1) for the current month where
    status="absent"



Any help would be appreciated .

Answer

I have tried this query and it works perfect :

select * from attendance
where emp_id=1 and year(date)=year(curdate()) and month(date)=month(curdate()) and status='present';
Comments