【问题标题】:PHP Propel groupBy two columnsPHP Propel 组按两列
【发布时间】:2012-04-10 17:16:08
【问题描述】:

我在 propel 中的 groupBy 有问题:

问题属于两个表。 一种称为显示,另一种称为客户显示类型。 在 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();

我该如何解决?

【问题讨论】:

    标签: php propel


    【解决方案1】:

    关于code,如果要使用多个groupBy,只需多次调用groupBy方法即可:

    $displays = PiDisplayQuery::create()
      ->filterByStationId($_object->getId())
      ->usePiCustomerDisplayTypeQuery()
        ->groupBy('PiCustomerDisplayType.Driver')
        ->groupBy('PiCustomerDisplayType.DriverOptions')
      ->endUse()
      ->find();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-04
      • 1970-01-01
      • 2012-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-08
      相关资源
      最近更新 更多