2

我在推进中遇到 groupBy 问题:

问题属于两个表。一种称为显示,另一种称为customerDisplayType。在 customerDisplayType 表中有两列“驱动程序”和“驱动程序选项”。我想在这两列上进行分组。因此结果可能如下所示:

Display1 -> with customerDisplayType driver "1" and driverOptions "xyz"
Display2 -> with customerDisplayType driver "1" and driverOptions "abc"
Display3 -> with customerDisplayType driver "2" and driverOptions "xyz"

我希望你知道我的意思...

到目前为止,我尝试过这样的事情:

    $displays = PiDisplayQuery::create()
    ->filterByStationId($_object->getId())    
    ->usePiCustomerDisplayTypeQuery()
        ->groupBy("CONCAT ".PiCustomerDisplayTypePeer::DRIVER.",".PiCustomerDisplayTypePeer::DRIVER_OPTIONS) // I also tried UNION instead of CONCAT
    ->endUse()
    ->find();

我该如何解决?

4

1 回答 1

2

关于代码,如果你想使用多个 groupBy,你只需要调用 groupBy 方法几次:

$displays = PiDisplayQuery::create()
  ->filterByStationId($_object->getId())
  ->usePiCustomerDisplayTypeQuery()
    ->groupBy('PiCustomerDisplayType.Driver')
    ->groupBy('PiCustomerDisplayType.DriverOptions')
  ->endUse()
  ->find();
于 2012-04-10T09:16:08.180 回答