0

我有一个查询需要返回 ShipDate 在一系列日期之间的记录。以下查询有效:

$query = "SELECT ECCustomerOrder.ShipDate, 
ECCustomers.Customer, 
ECCustomerOrder.PO, 
ECCustomerOrder.TotalCases, 
ECCustomerOrder.order_number
FROM ECCustomerOrder INNER JOIN ECCustomers ON ECCustomerOrder.ID = ECCustomers.ID
WHERE ECCustomerOrder.ShipDate >= $todayMinus";

$todayMinus 是脚本前面设置的一个 php 变量,它采用当前日期并减去 15 天。我无法上班的情况如下:

$query = "SELECT ECCustomerOrder.ShipDate, 
ECCustomers.Customer, 
ECCustomerOrder.PO, 
ECCustomerOrder.TotalCases, 
ECCustomerOrder.order_number
FROM ECCustomerOrder INNER JOIN ECCustomers ON ECCustomerOrder.ID = ECCustomers.ID
WHERE ECCustomerOrder.ShipDate BETWEEN $todayMinus AND $todayPlus";

此 SQL 查询返回 $todayMinus 和 $todayPlus 的 ShipDates 之间的记录的正确语法是什么?

4

1 回答 1

3

assuming you're using plain dates, you'll have to quote them.

e.g.

ShipDate BETWEEN 2013-01-01 AND 2013-02-19

is incorrect, because 2013-01-01 is a substraction, you're actually doing

ShipDate BETWEEN 2011 AND 1992

try

ShipDate BETWEEN '$todayMinus' AND '$todayPlus'
于 2013-02-19T19:15:18.103 回答