我在推进中遇到了groupBy的问题:
问题属于两个表。 一个称为显示,另一个称为customerDisplayType。 在customerDisplayType表中有两列'driver'和'driverOptions'。 我想分组这两个专栏。 所以结果看起来像这样:
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();
我该如何解决?
答案 0 :(得分:2)
关于code,如果你想使用多个groupBy,你只需要多次调用groupBy方法:
$displays = PiDisplayQuery::create()
->filterByStationId($_object->getId())
->usePiCustomerDisplayTypeQuery()
->groupBy('PiCustomerDisplayType.Driver')
->groupBy('PiCustomerDisplayType.DriverOptions')
->endUse()
->find();