SELECT person.sex
	,IF(person.sex = 1,'ชาย','หญิง')AS เพศ
	,COUNT(person.pid) as รวม
	,SUM(CASE WHEN YEAR(person.birth) = '2013' THEN 1 ELSE 0 END) as '2556'
	,SUM(CASE WHEN YEAR(person.birth) = '2012' THEN 1 ELSE 0 END) as '2555'
	,sum(CASE WHEN YEAR(person.birth) = '2011' THEN 1 ELSE 0 END) as '2554'
	,sum(CASE WHEN YEAR(person.birth) = '2010' THEN 1 ELSE 0 END) as '2553'
	,sum(CASE WHEN YEAR(person.birth) = '2009' THEN 1 ELSE 0 END) as '2552'
	,sum(CASE WHEN YEAR(person.birth) = '2008' THEN 1 ELSE 0 END) as '2551'
	,sum(CASE WHEN YEAR(person.birth) = '2007' THEN 1 ELSE 0 END) as '2550'
FROM person
	LEFT JOIN persondeath ON person.pcucodeperson = persondeath.pcucodeperson and person.pid = persondeath.pid
WHERE persondeath.pid IS NULL
GROUP BY person.sex;