MySQL之间的日期格式

时间:2010-08-20 16:11:29

标签: mysql

我有查询...

SELECT COUNT(order_id) as orders, 
       SUM(order_total) as sales 
  FROM uc_orders 
 WHERE FROM_UNIXTIME(created) BETWEEN "2010-08-14" AND "2010-08-15" 
   AND order_status = "payment_received"

问题是没有从提供的日期返回订单。我没有收到任何SQL错误。 BETWEEN有什么我做错了吗?

1 个答案:

答案 0 :(得分:1)

您的查询无需任何更改即可正常工作,甚至无需添加小时/分钟/秒。我刚刚在MySQL 5.1上测试过它。

您更有可能在这些日期与order_status =“payment_received”之间没有任何数据

mysql> SELECT COUNT(session_id) as orders FROM phpbb_sessions 
WHERE FROM_UNIXTIME(session_time) BETWEEN "2010-08-20" AND "2010-08-21";
+--------+
| orders |
+--------+
|    224 | 
+--------+
1 row in set (0.00 sec)

mysql> SELECT COUNT(session_id) as orders FROM phpbb_sessions 
WHERE FROM_UNIXTIME(session_time) BETWEEN "2010-08-20 00:00:00" AND "2010-08-21 23:59:59";
+--------+
| orders |
+--------+
|    224 | 
+--------+
1 row in set (0.00 sec)