我已尝试将此引用用于我的select语句,但它似乎不起作用:Fetching single row, single column with PDO
我的sql查询如下所示:
$sql = "SELECT sum(cost) FROM inventory t1 WHERE t1.`date` = (SELECT max(t2.`date`) FROM inventory t2 WHERE t1.`product` = t2.`product`)";
结果应返回单个值(库存中产品的所有当前成本的总和)。
我试过这个没有运气:
$stmt=$pdo_dbh->prepare($sql);
$stmt->execute();
$result = $stmt->fetch();
编辑:这是表格的样子
Table name: inventory
id | cost | product | date