我正在尝试使用推进标准构建以下查询:
SELECT *
FROM mytable
WHERE facility_id IN (4,7)
GROUP BY housing_id
HAVING COUNT(DISTINCT facility_id) = 2;
推进标准:
$criteria->add(HousingsHousingFacilitiesPeer::HOUSING_FACILITY_ID, $facility_filter, Criteria::IN);
$criteria->addGroupByColumn(HousingsHousingFacilitiesPeer::HOUSING_ID);
$criteria->addHaving(
$criteria->getNewCriterion(
HousingsHousingFacilitiesPeer::HOUSING_ID,
'COUNT(DISTINCT housings_housing_facilities.HOUSING_FACILITY_ID) = 2',
Criteria::CUSTOM
)
);
但查询确实返回任何结果。
我是否正确使用了自定义标准?