我需要选择从今天中午12点到次日凌晨5点的每日销售额。
示例:2018-11-08 12:00
至2018-11-09 05:00
(于2018-11-08启动)
我能够在23:59
之前检索每日销售额,但无法获取第二天的05:00。
我有Orders
表,其数据类型为Order_date
,日期时间格式为TEXT
答案 0 :(得分:0)
我相信可以使用以下内容:-
SELECT * FROM orders
WHERE order_date
BETWEEN (strftime('%Y-%m-%d','now')||' 12:00')
AND (strftime('%Y-%m-%d','now','+1 days')||' 05:00')
;
DROP TABLE IF EXISTS orders;
CREATE TABLE IF NOT EXISTS orders (order_date TEXT);
INSERT INTO orders (order_date) VALUES
(strftime('%Y-%m-%d','now','-1 days')||' 11:59'), -- before
(strftime('%Y-%m-%d','now')||' 00:00'), -- before
(strftime('%Y-%m-%d','now')||' 11:59'), -- before (just)
(strftime('%Y-%m-%d','now')||' 12:00'), --*** included
(strftime('%Y-%m-%d','now')||' 23:59'), --*** included
(strftime('%Y-%m-%d','now','+1 days')||' 05:00'), --**** included
(strftime('%Y-%m-%d','now','+1 days')||' 05:01') -- after (just)
;
SELECT * FROM orders
WHERE order_date
BETWEEN (strftime('%Y-%m-%d','now')||' 12:00')
AND (strftime('%Y-%m-%d','now','+1 days')||' 05:00')
;