我正在尝试获取此查询的结果:
// 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
我想Propel在选择中添加了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 !!
答案 0 :(得分:0)
您需要为聚合函数使用别名,请尝试:
$min = TourCmsInventoryQuery::create()
->withColumn('MIN(inventory_date)', 'MinInventoryDate')
->filterByExtraId($tour->getId())
->groupByExtraId()
->find();