过滤掉重复项然后使用 Propel 获取记录总数

Filtering out duplicates then getting the total number of records with Propel

我有一个 MySQL 数据库,我正在使用 Propel。我是 Propel 的新手,所以我的语法不是很好。我想做的是找到一列中的记录总数,从结果中过滤掉重复项。

我可以使用

轻松获得记录总数
$distinctCount = TblUserAnswersQuery::create()
->setDistinct('User_Id')
->find()
->count();

但这只是给我记录的总数。如您所见,我已经尝试使用 setDistinct() 但这仍然只是 returns 记录总数而没有过滤掉重复项。

要做到这一点是 SQL,我可以使用这个:

SELECT COUNT(distinct User_Id) AS distinctCount FROM Tbl_User_Answers

据 Propel 所知,我没有收到任何错误,但显然我没有收到任何错误,因为我的语法错误。我真正需要的是知道如何将上面的 SQL 转换为 Propel 语法。

你可以必须指定不同的列,然后添加不同的,你也不需要 find :

$distinctCount = TblUserAnswersQuery::create()
  ->select(['User_Id'])
  ->distinct()
  ->count();