2
4

1 回答 1

1

我相信这是您想要的 SQl(无论如何似乎在我的SQL Fiddle中工作):

SELECT car_id FROM
  (SELECT COUNT(car_id) AS feature_count, car_id FROM feature
    WHERE feature IN ('f1', 'f2', 'f3') GROUP BY car_id
  ) car_features
WHERE car_features.feature_count=3

现在要在 Propel 中获得它,您需要执行以下操作:

$features = array("f1", "f2", "f3");
$featureCount = FeatureQuery::create()
  ->withColumn("COUNT(car_id)", "feature_count")
  ->add(FeaturePeer::FEATURE, $features, Criteria::IN)
  ->addGroupBy(CarPeer::ID);
$cars = CarQuery::create()
  ->addSelectQuery($featureCount, "car_features")
  ->where("car_features.feature_count = ?", sizeof($features))
  ->find();
于 2013-01-10T03:02:29.927 回答