Php 如何使用Prope获得最大和/或最小聚合mysql函数?
我正在尝试获取此查询的结果:Php 如何使用Prope获得最大和/或最小聚合mysql函数?,php,propel,Php,Propel,我正在尝试获取此查询的结果: // SELECT MIN(`inventory_date`) FROM `tour_cms_inventory` WHERE extra_id = 52 使用此代码: $min = TourCmsInventoryQuery::create() ->withColumn('MIN(inventory_date)') ->filterByExtraId($tour->
// SELECT MIN(`inventory_date`) FROM `tour_cms_inventory` WHERE extra_id = 52
使用此代码:
$min = TourCmsInventoryQuery::create()
->withColumn('MIN(inventory_date)')
->filterByExtraId($tour->getId())
->groupByExtraId()
->find();
但我得到了这个错误:
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1140 In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'mkte_circuitos_imp.tour_cms_inventory.id'; this is incompatible with sql_mode=only_full_group_by in C:\laragon\www\mkte_circuitos\vendor\propel\propel\src\Propel\Runtime\Connection\StatementWrapper.php:194
我猜推进是在选择中添加了pk(id)(mkte_circuitos_imp.tour_cms_inventory.id)
我做错了什么
致意
编辑
我也尝试这样做:
$con = \Propel\Runtime\Propel::getWriteConnection(TourCmsInventoryTableMap::DATABASE_NAME);
$con->useDebug(true);
$sql = 'SELECT MIN(inventory_date) FROM tour_cms_inventory WHERE extra_id=:extra_id';
$stmt = $con->prepare($sql);
$rs = $stmt->execute([':extra_id'=>$tour->getId()]);
但是。。。返回true 如果聚合函数需要别名,请尝试:
$min = TourCmsInventoryQuery::create()
->withColumn('MIN(inventory_date)', 'MinInventoryDate')
->filterByExtraId($tour->getId())
->groupByExtraId()
->find();
如果聚合函数需要别名,请尝试:
$min = TourCmsInventoryQuery::create()
->withColumn('MIN(inventory_date)', 'MinInventoryDate')
->filterByExtraId($tour->getId())
->groupByExtraId()
->find();
$stmt->execute()
不返回查询结果。查看$stmt->fetch()
。不,fetch()不起作用。我决定使用limit(1)和OrderBy。。。感谢$stmt->execute()
没有返回查询结果。查看$stmt->fetch()
。不,fetch()不起作用。我决定使用limit(1)和OrderBy。。。谢谢