device_id ,water_meter_type,device_no, site_id, sys_id, building_id,
province, city, region, community, customer_id, meter_no, meter_file_no,
device_type_id, concentrator_id,collector_id, `location`,valve_measuring_code,
reading_measuring_code,date_create
d.id as device_id ,
wmt.parent_id as water_meter_type ,
d.device_no as device_no ,
d.site_id as site_id ,
d.sys_id as sys_id ,
d.building_id as building_id ,
b.province as province ,
b.city as city ,
b.region as region,
b.community as community ,
d.customer_id as customer_id ,
d.water_meter_no as meter_no ,
d.water_meter_file_no as meter_file_no,
d.device_type as device_type_id ,
wrd.concentrator_id as concentrator_id ,
wrd.collector_id as collector_id ,
d.loc_desc as location,
wmt.valve_measuring_code as valve_measuring_code ,
wmt.reading_measuring_code as reading_measuring_code,
d.date_create as date_create
d.`status` = 1
and wmt.`status` = 1
and wmt.valve_measuring_code is not null
and wmt.reading_measuring_code is not null
and wmt.parent_id in (1,2)
SELECT
FROM
WHERE
sc_w_meter_type wmt
left join sc_device d on (d.`status` = 1 and wmt.device_type_id = d.device_type)
left join sc_water_related_device wrd on (wrd.device_id =d.id)
left join sc_building b on (d.building_id = b.id)