是否可以在一个查询中有多个 HAVING?
这是我的示例查询:
SELECT household_tbl.household_connector_id AS h_id
, (
SELECT COUNT(household_connector_id)
FROM household_tbl
WHERE household_connector_id = h_id
AND hh_phic_status = 1
AND age >= 21
AND age_category = "Year"
) + (
SELECT COUNT(hh_members_connector_id)
FROM tbl_household_members
WHERE household_connector_id = h_id
AND hh_phic_status = 1
AND hh_age >= 21
AND hh_age_category = "Year"
) AS total_phic
, (
SELECT COUNT(household_connector_id)
FROM household_tbl
WHERE household_connector_id = h_id
AND hh_phic_status = 1
AND age >= 21
AND age_category = "Year"
AND (
hh_phic_membership_category = "ng sponsored"
OR hh_phic_membership_category = "Sponsored-NG(DOH)"
)
) + (
SELECT COUNT(hh_members_connector_id)
FROM tbl_household_members
WHERE household_connector_id = h_id
AND hh_phic_status = 1
AND hh_age >= 21
AND hh_age_category = "Year"
AND (
hh_phic_membership_category = "ng sponsored"
OR hh_phic_membership_category = "Sponsored-NG(DOH)"
)
) AS ng_sponsored
FROM household_tbl
WHERE barangay = "'.$barangay.'"
HAVING total_phic <> 0
我也想要“拥有 ng_support <> 0”
谢谢!