jeudi 20 octobre 2016

I Want Short My Sql Query

select YEAR(date) as year,

(select Count(a.status) as absent from attendance as a where a.status = 'absent' and MONTH(a.date) = 1 and YEAR(a.date) = year and a.employeeID = attendance.employeeID) as jan,

(select Count(b.status) as absent from `attendance` as b
where b.`status` = 'absent' and MONTH(b.date) = 2 and YEAR(b.date) = year and b.`employeeID` = `attendance`.employeeID) as feb,

(select Count(c.status) as absent from `attendance` as c
where c.`status` = 'absent' and MONTH(c.date) = 3 and YEAR(c.date) = year and c.`employeeID` = `attendance`.employeeID) as mar,

(select Count(d.status) as absent from `attendance` as d
where d.`status` = 'absent' and MONTH(d.date) = 4 and YEAR(d.date) = year and d.`employeeID` = `attendance`.employeeID) as apr,

(select Count(e.status) as absent from `attendance` as e
where e.`status` = 'absent' and MONTH(e.date) = 5 and YEAR(e.date) = year and e.`employeeID` = `attendance`.employeeID) as may,

(select Count(f.status) as absent from `attendance` as f
where f.`status` = 'absent' and MONTH(f.date) = 6 and YEAR(f.date) = year and f.`employeeID` = `attendance`.employeeID) as june,

(select Count(g.status) as absent from `attendance` as g
where g.`status` = 'absent' and MONTH(g.date) = 7 and YEAR(g.date) = year and g.`employeeID` = `attendance`.employeeID) as july,

(select Count(h.status) as absent from `attendance` as h
where h.`status` = 'absent' and MONTH(h.date) = 8 and YEAR(h.date) = year and h.`employeeID` = `attendance`.employeeID) as aug,

(select Count(i.status) as absent from `attendance` as i
where i.`status` = 'absent' and MONTH(i.date) = 9 and YEAR(i.date) = year and i.`employeeID` = `attendance`.employeeID) as sept,

(select Count(j.status) as absent from attendance as j where j.status = 'absent' and MONTH(j.date) = 10 and YEAR(j.date) = year and j.employeeID = attendance.employeeID) as octm,

(select Count(k.status) as absent from attendance as k where k.status = 'absent' and MONTH(k.date) = 11 and YEAR(k.date) = year and k.employeeID = attendance.employeeID) as nov,

(select Count(l.status) as absent from attendance as l where l.status = 'absent' and MONTH(l.date) = 12 and YEAR(l.date) = year and l.employeeID = attendance.employeeID) as decm,

(select Count(a.status) as absent from attendance as a where a.status = 'absent' and YEAR(a.date) = year and a.employeeID = attendance.employeeID) as yearWise from attendance where status = 'absent' and employeeID = '1-4014' group by year ORDER BY 'year' desc



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire