select sum(dayno) as total_absence, type_no ,employee_id , "รอบที่ 1"
from absence
where employee_id='123456' and
( (year(stdate) >= '2011' and year(stdate) <= '2012' ) and ( month(stdate) >= '10' and month(stdate) <= '03' ) and (day(stdate) >= '01' and day(stdate) <= '31') ) and
( (year(endate) >= '2011' and year(endate) <= '2012' ) and ( month(endate) >= '01' and month(endate) <= '06' ) and (day(endate) >= '01' and day(endate) <= '31'))
group by employee_id , type_no
select sum(dayno) as total_absence, type_no ,employee_id , "รอบที่ 2"
from absence
where employee_id='123456' and
( year(stdate) == '2012' and ( month(stdate) >= '04' and month(stdate) <= '09' ) and (day(stdate) >= '01' and day(stdate) <= '31') ) and
( year(endate) == '2012' and ( month(endate) >= '04' and month(endate) <= '09' ) and (day(endate) >= '01' and day(endate) <= '31') )
group by employee_id , type_no
select sum(dayno) as total_absence, type_no ,employee_id ,count(*) as ab_number
from absence
where employee_id='123456' and
( stdate between '2012-04-01' and '2012-09-30' ) and
( endate between '2012-04-01' and '2012-09-30' )
group by employee_id , type_no
order by a_id
limit (ab_number - 1)
select sum(dayno) as total_absence, type_no ,employee_id ,
(select count(*) from absence where employee_id='123456' and
( stdate between '2012-04-01' and '2012-09-30' ) and
( endate between '2012-04-01' and '2012-09-30' )
group by employee_id , type_no
) as ab_number
from absence
where employee_id='123456' and
( stdate between '2012-04-01' and '2012-09-30' ) and
( endate between '2012-04-01' and '2012-09-30' )
group by employee_id , type_no
order by a_id
limit (ab_number - 1)
error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(ab_number - 1)' at line 1