บัญชี 1 ยัง Error Script ตรงนี้อยู่
select cast(v.village_moo as integer) as village_moo_int,
v.address_id,v.village_moo,v.village_id,v.village_name,v.latitude,v.longitude,t.name as tmb_name,
count(distinct h.house_id) as house_count, count(distinct p.person_id) as person_count ,
count(ps1.person_id) as male_count , count(ps2.person_id) as female_count ,
count(ps3.person_id) as death_count , count(ps3.person_id) as family_count
from village v
left outer join house h on h.village_id = v.village_id
left outer join person p on p.house_id = h.house_id and p.house_id not in (439,1891)
left outer join person ps1 on ps1.person_id = p.person_id and ps1.sex = '1' and ps1.death='N'
left outer join person ps2 on ps2.person_id = p.person_id and ps2.sex = '2' and ps2.death='N'
left outer join person ps3 on ps3.person_id = p.person_id and ps3.death = 'Y'
left outer join thaiaddress t on t.addressid = v.address_id and t.codetype='3'
group by v.address_id,v.village_moo,v.village_id,v.village_name ,v.latitude,v.longitude,t.name
order by v.address_id,village_moo_int