我正在尝试将两个查询合并为一个查询。但我没有取得任何成功。
查询1:
SELECT
District.PkLocID AS districtId,
District.LocName AS districtName,
COUNT(DISTINCT UC.PkLocID) AS reported
FROM
tbl_locations AS District
INNER JOIN tbl_locations AS UC ON District.PkLocID = UC.district_id
INNER JOIN tbl_warehouse ON UC.PkLocID = tbl_warehouse.locid
INNER JOIN tbl_wh_data ON tbl_warehouse.wh_id = tbl_wh_data.wh_id
INNER JOIN stakeholder ON tbl_warehouse.stkofficeid = stakeholder.stkid
WHERE
stakeholder.lvl = 6
AND tbl_warehouse.stkid = 1
AND District.province_id = 1
AND tbl_wh_data.report_month = 02
AND tbl_wh_data.report_year = 2014
AND tbl_wh_data.wh_issue_up IS NOT NULL
GROUP BY
District.PkLocID
ORDER BY
districtId ASC
查询2:
SELECT
COUNT(DISTINCT UC.PkLocID) AS totalWH,
District.PkLocID
FROM
tbl_locations AS District
INNER JOIN tbl_locations AS UC ON District.PkLocID = UC.district_id
INNER JOIN tbl_warehouse ON UC.PkLocID = tbl_warehouse.locid
INNER JOIN stakeholder ON tbl_warehouse.stkofficeid = stakeholder.stkid
WHERE
stakeholder.lvl = 6
AND tbl_warehouse.stkid = 1
AND District.province_id = 1
GROUP BY
District.PkLocID
ORDER BY
District.PkLocID ASC
我尝试过应用子查询和连接,但它显示的结果不正确。