I have an mysql query:
SELECT count(*) as `present_days`
FROM tbl_intime_status
WHERE employee_status = 'Out' and
present_status = 'Full Day' and
date LIKE '%/"+month2+"/"+year1+"' and
employee_id="+ EmpId+
From this query I am getting no. of Full Day
present.
I have present_status= 'Half Day'
& present_status = 'Full Day'
in my database records.
How to count 'Full Day' + 'Half Day'?
If you want the counts separate you can do this
SELECT present_status, count(*) as `present_days`
FROM tbl_intime_status
WHERE employee_status = 'Out' and
present_status IN ('Full Day','Half Day')
date LIKE '%/"+month2+"/"+year1+"' and
employee_id="+ EmpId+
GROUP BY present_status
If you want the total of both do this
SELECT count(*) as `present_days`
FROM tbl_intime_status
WHERE employee_status = 'Out' and
present_status IN ('Full Day','Half Day')
date LIKE '%/"+month2+"/"+year1+"' and
employee_id="+ EmpId+
try, don'tforget to escape the date
column since it is a reserved word.
SELECT present_status, count(*) as `present_days`
FROM tbl_intime_status
WHERE employee_status = 'Out' and
present_status IN ('Full Day','Half Day')
`date` LIKE '%/"+month2+"/"+year1+"' and
employee_id = " + EmpId + "
GROUP BY present_status
I want to try this to see if it works:
...
present_status in ('Full Day', 'Half Day' )
...
The grammar can be found here : SQL IN Operator.
Just add it to your where clause, either with IN
:
...
WHERE present_status IN ('Full Day','Half Day')
...
or with OR
:
...
WHERE (present_status = 'Full Day' OR present_status = 'Half Day')
...
Is this what you are looking for:
SELECT count(*) as present_days
FROM tbl_intime_status
WHERE employee_status = 'Out'
and present_status IN ('Full Day', 'Half Day')
and date LIKE '%/"+month2+"/"+year1+"'
and employee_id="+ EmpId
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With