我正在使用PHP和SQL根据每周时段创建统计信息摘要。
我最初认为所有项目都具有相同的日期,下面的代码适用于那种情况。
$result1 = mysql_query("SELECT * FROM phoneappdetail WHERE salebarn = 'OSI' AND saledate = '2012-06-6' ORDER BY wtcode ");
但是现在我发现我需要查询的项目有不同的日期。
如何更改查询以获取2012-06-6和2012-06-12之间的日期,而不仅仅是2012-06-6的日期?
答案 0 :(得分:3)
使用SQL BETWEEN子句:
SELECT * FROM phoneappdetail WHERE salebarn = 'OSI' AND (saledate BETWEEN '2012-06-6' AND '2012-06-12') ORDER BY wtcode
答案 1 :(得分:0)
saledate between '2012-06-6' and '2012-06-12'
答案 2 :(得分:0)
$result1 = mysql_query("SELECT * FROM phoneappdetail WHERE salebarn = 'OSI' AND saledate > '2012-06-6' AND saledate < '2012-06-12' ORDER BY wtcode ");