无法在zf2中使用Range添加Group by

时间:2015-12-17 12:17:19

标签: php mysql zend-framework2

我的查询无法使用其显示未知列我在zend Framework 2中的查询

$select = new Select('dining_table_reservation');
        $select->columns(array('range'=>new \Zend\Db\Sql\Expression("CONCAT(5*floor(dining_table.SeatingCapacity/5),'-',5*floor(dining_table.SeatingCapacity/5) + 5)"),'Avgtime'=>new \Zend\Db\Sql\Expression('avg(timestampdiff(SECOND, '.$dtr.'.StartTime, '.$dtr.'.EndTime))')));
        $select->join($dt, "$dtr.TableId=$dt.TableId", array('SeatingCapacity'),'INNER');
        $select->group(1);
        $select->order($dt.'.SeatingCapacity');

我的查询外观

SELECT CONCAT(5*floor(dining_table.SeatingCapacity/5),'-',5*floor(dining_table.SeatingCapacity/5) + 5) AS "range", avg(timestampdiff(SECOND, dining_table_reservation.StartTime, dining_table_reservation.EndTime)) AS "Avgtime", "dining_table"."SeatingCapacity" AS "SeatingCapacity" FROM "dining_table_reservation" INNER JOIN "dining_table" ON "dining_table_reservation"."TableId"="dining_table"."TableId" GROUP BY "1" ORDER BY "dining_table"."SeatingCapacity" ASC

显示错误:

  

"无法执行声明(42S22 - 1054 - 未知列   \ u0027在\ u0027group statement \ u0027)"

我该怎么办?

1 个答案:

答案 0 :(得分:0)

数据库中的表中没有第1列,您需要为group by设置exists列。你可以向你展示数据库结构吗?