我陷入了疑问,实际上我有一个搜索框,提供开始日期时间和结束日期时间,例如2015-09-18 13:00:00
至2015-09-21 17:00:00
我尝试了查询
select l.date, l.center_name, l.center_office, l.offline, l.online, l.category,
(select service_name from services_master where service_id = w.services) as servicename,
(select vendor_name from vendor_master where vendor_id = w.vendor) as vendorname
from lease_reports l,wan_entries w
where l.center_id = '7' and
w.id = l.center_id and
l.date between $startdatetime and $endatetime
我没有得到确切的结果,结果包括这两个日期之间的所有时间。我想要用户提供的确切间隔时间的明智行
答案 0 :(得分:0)
确切的语法取决于您使用的数据库(请参阅stackoverflow.com/questions/1658340/sql-query-to-group-by-day),
但您正在寻找的逻辑/伪代码如下。
...
AND day(l.date) BETWEEN day($startdatetime) and day($endatetime)
AND time(l.date) BETWEEN time($startdatetime) and time($endatetime)
GROUP BY day(l.date)
但是,如果您单独查询日期和时间,最终用户可能会更清楚。