我正在尝试从MySQL服务器获取数据,这是在目前的两个给定日期之间我正在执行这些查询获得所需的结果&如此丰富的成果:
SELECT mdn,recharge_status_code, recharge_status_code_desc, date_time
FROM impressions_log
WHERE recharge_status_code in ('515')
AND date(date_time) IN ('2014-05-18','2014-05-19','2014-05-20','2014-05-21','2014-05-22')
我还能够找到另外一个查询解决方案,但它既没有给出任何错误也没有任何结果:
SELECT mdn,recharge_status_code, recharge_status_code_desc, date_time, retry_status
FROM impressions_log
WHERE recharge_status_code IN ('515') AND date(date_time) = DATEDIFF('2014-05-18','2014-05-24')
答案 0 :(得分:0)
试试这个:
SELECT
mdn,
recharge_status_code,
recharge_status_code_desc,
date_time,
retry_status
FROM impressions_log
WHERE recharge_status_code in ('515')
AND DATE(date_time) BETWEEN '2014-05-18' AND '2014-05-24';
答案 1 :(得分:0)
假设您的日期是连续的,您可以更改查询以使用BETWEEN
或相应地使用>
和<
。
SELECT mdn,recharge_status_code, recharge_status_code_desc, date_time
FROM impressions_log
WHERE recharge_status_code in ('515')
AND date(date_time) BETWEEN '2014-05-18' AND '2014-05-22'
或者:
SELECT mdn,recharge_status_code, recharge_status_code_desc, date_time
FROM impressions_log
WHERE recharge_status_code in ('515')
AND date_time >= '2014-05-18' AND date_time < '2014-05-23'
我更喜欢后者,因为你不必进行任何演员。