ERROR: แบบนี้แก้อย่างไรคับ
[Err] 1064 - 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 '{$whereSetGroupAge}
AND p.death = 'N' AND p.house_regist_type_id IN {$_typeArea' at line 5
----------------------------------------------------------------------------------------------------------------------------------
SELECT * FROM (SELECT COUNT(p.person_id) AS cc
FROM person p,house h,village v
WHERE p.house_id = h.house_id AND h.village_id = v.village_id
#AND v.village_moo <> '0'
{$whereSetGroupAge}
AND p.death = 'N' AND p.house_regist_type_id IN {$_typeArea}) AS t1,
(SELECT
COUNT(person_id) AS cc_nutrition
,COUNT(IF(nutrition_level=1,1,NULL)) AS nutri_level_1
,COUNT(IF(nutrition_level=2,1,NULL)) AS nutri_level_2
,COUNT(IF(nutrition_level=3,1,NULL)) AS nutri_level_3
,COUNT(IF(nutrition_level=4,1,NULL)) AS nutri_level_4
,COUNT(IF(nutrition_level=5,1,NULL)) AS nutri_level_5
,COUNT(IF(nutrition_level NOT IN (1,2,3,4,5),1,NULL)) AS nutri_level_etc
,COUNT(IF(height_level=1,1,NULL)) AS height_level_1
,COUNT(IF(height_level=2,1,NULL)) AS height_level_2
,COUNT(IF(height_level=3,1,NULL)) AS height_level_3
,COUNT(IF(height_level=4,1,NULL)) AS height_level_4
,COUNT(IF(height_level=5,1,NULL)) AS height_level_5
,COUNT(IF(height_level NOT IN (1,2,3,4,5),1,NULL)) AS height_level_etc
,COUNT(IF(bmi_level=1,1,NULL)) AS bmi_level_1
,COUNT(IF(bmi_level=2,1,NULL)) AS bmi_level_2
,COUNT(IF(bmi_level=3,1,NULL)) AS bmi_level_3
,COUNT(IF(bmi_level=4,1,NULL)) AS bmi_level_4
,COUNT(IF(bmi_level=5,1,NULL)) AS bmi_level_5
,COUNT(IF(bmi_level=6,1,NULL)) AS bmi_level_6
,COUNT(IF(bmi_level NOT IN (1,2,3,4,5),1,NULL)) AS bmi_level_etc
FROM
(SELECT
*
FROM
(SELECT
a2.person_id,a1.nutrition_level,a1.height_level,a1.bmi_level,nutrition_date
FROM person_wbc_nutrition a1,person_wbc a2
WHERE a1.person_wbc_id = a2.person_wbc_id
AND (discharge = 'N' OR discharge IS NULL)
AND a1.nutrition_date BETWEEN '{$Year_section_a}' AND '{$Year_section_b}'
AND a1.person_wbc_nutrition_id = (SELECT MAX(person_wbc_nutrition_id) FROM person_wbc_nutrition WHERE person_wbc_id = a2.person_wbc_id AND nutrition_date BETWEEN '{$Year_section_a}' AND '{$Year_section_b}' )
UNION
SELECT
b2.person_id,b1.nutrition_level,b1.height_level,b1.bmi_level,nutrition_date
FROM person_epi_nutrition b1,person_epi b2
WHERE b1.person_epi_id = b2.person_epi_id
AND (discharge = 'N' OR discharge IS NULL)
AND b1.nutrition_date BETWEEN '{$Year_section_a}' AND '{$Year_section_b}'
AND b1.person_epi_nutrition_id = (SELECT MAX(person_epi_nutrition_id) FROM person_epi_nutrition WHERE person_epi_id = b2.person_epi_id AND nutrition_date BETWEEN '{$Year_section_a}' AND '{$Year_section_b}' )
) AS tmp
WHERE nutrition_date BETWEEN '{$Year_section_a}' AND '{$Year_section_b}'
AND person_id IN (SELECT p.person_id FROM person p,house h,village v WHERE p.house_id = h.house_id AND h.village_id = v.village_id AND v.village_moo <> '0'
{$whereSetGroupAge}
AND p.death = 'N'
AND p.house_regist_type_id IN {$_typeArea})
GROUP BY person_id
) AS t2 ) AS t4