我正在处理一个查询,其中我会得到meter numbers
的列表以及subdivision names
。
但是,当我运行查询时,它会根据不同的电表号码给出相同的subdivision
名称。
查询
SELECT DISTINCT ms.`id` AS 'meter_id', ms.`meter_msn` AS 'Meter_Serial_Number', u.`name` AS 'Issued_To'
,ps.`name` AS 'Store', sd.`name` AS 'Name',ms.`historic` AS 'Meter_Version'
FROM `meters` ms
INNER JOIN `ogp_header` ogph ON ms.`issued_user` = ogph.`issuer`
INNER JOIN `project_store` ps ON ogph.`store_id` = ps.`id`
INNER JOIN `user` u ON `ogph`.`issuer` = u.`id`
INNER JOIN `issue_meters` im ON ps.`id` = im.`store_id`
INNER JOIN `survey_hesco_subdivision` sd ON im.`sub_division` =
sd.`sub_div_code`
WHERE ms.`meter_status` = 'Installation Ready' AND ms.`id` NOT IN (SELECT
DISTINCT ogpd.`meter_id` FROM `ogp_detail` ogpd WHERE ogpd.`flag` IN (1,2))
GROUP BY ms.`id`
ORDER BY ms.`id`
结果是
所有这6米来自不同的分部(结果中的NAME)。如何以一种不同的细分名称来安排查询?
任何帮助都将受到高度赞赏。