看看这个:
我的 SQL 查询是:
SELECT @rownum := @rownum + 1 AS ID, SKU, SUM(Quantity) FROM orders, (SELECT @rownum := 0) r
WHERE ShipDate BETWEEN 01-05-2013 AND 11-05-2013
GROUP BY SKU
在我的代码中,我正在执行以下操作:
$sql = "SELECT @rownum := @rownum + 1 AS ID, SKU, SUM(Quantity)
FROM orders, (SELECT @rownum := 0) r
WHERE ShipDate BETWEEN {$from_date } AND {$to_date }
GROUP BY SKU";
我想选择介于两个值之间的数据。
ShipDate
是文本字段而不是日期字段。我检查了表,它保存了数据,但 MySQL 返回 null。
为什么?我做错了什么?
如何更新我的 PHP 代码?
这段代码:
"SELECT @rownum := @rownum + 1 AS ID, SKU, SUM(Quantity)
FROM orders, (SELECT @rownum := 0) r
WHERE STR_TO_DATE(ShipDate,'%d-%m-%Y') BETWEEN {$from_date } AND {$to_date }
GROUP BY SKU";
不适合我。
请帮我。