简体   繁体   English

为什么此查询返回2013年的项目?

[英]Why Does This Query Return Items from 2013?

This query: 该查询:

SELECT 
        mantis_bug_history_table.bug_id,
        mantis_category_table.name, 
        FROM_UNIXTIME(mantis_bug_table.date_submitted, "%m-%d-%Y"),
        FROM_UNIXTIME(mantis_bug_history_table.date_modified, "%m-%d-%Y"),
        ROUND((mantis_bug_history_table.date_modified- mantis_bug_table.date_submitted)/ 86400, 1) as day_difference
    FROM 
        (mantis_bug_table INNER JOIN mantis_bug_history_table ON mantis_bug_table.id = mantis_bug_history_table.bug_id) 
    INNER JOIN 
        mantis_category_table ON mantis_bug_table.category_id = mantis_category_table.id 
    WHERE
        FROM_UNIXTIME(mantis_bug_table.date_submitted, "%m-%d-%Y")
    BETWEEN '10/01/2014' AND '12/31/2014' 
    AND
        (((mantis_bug_history_table.field_name)="status") 
    AND 
        ((mantis_bug_history_table.new_value)="100")) 
    OR 
        (((mantis_bug_history_table.field_name)="new task")) 
    ORDER BY 
        mantis_bug_table.category_id, mantis_bug_table.date_submitted

Returns mostly valid data but also a couple of rows with these dates: 返回大多数有效数据,但也返回带有这些日期的两行:

'39', 'Contracting', '12-12-2013', '01-14-2014', '32.7'
'40', 'Contracting', '12-12-2013', '01-14-2014', '32.7'
'41', 'Contracting', '12-19-2013', '03-12-2014', '82.9'
'42', 'Contracting', '12-31-2013', '01-14-2014', '13.9'

Can anyone explain why the between statement is not working 100%? 谁能解释为什么between语句不能100%工作?

WHERE FROM_UNIXTIME(mantis_bug_table.date_submitted, "%m-%d-%Y")
      BETWEEN '10/01/2014' AND '12/31/2014' 

Look like rather different date formats to me.... one with - separator, the other with a / separator 对我来说,日期格式似乎完全不同。...一种使用-分隔符,另一种使用/分隔符

To me, it looks like the OR part of your WHERE clause is going to bring in data you don't want. 对我来说,您的WHERE子句的OR部分似乎将带来您不需要的数据。 Let's reformat it. 让我们重新格式化。

WHERE 
    FROM_UNIXTIME(mantis_bug_table.date_submitted, "%m-%d-%Y") 
        BETWEEN '10/01/2014' AND '12/31/2014'
    AND (((mantis_bug_history_table.field_name)="status")
         AND ((mantis_bug_history_table.new_value)="100"))
    OR (((mantis_bug_history_table.field_name)="new task"))

It boils down to 归结为

WHERE 
    FROM_UNIXTIME ...
    AND ( ... AND ...)
    OR  ( ... )

IMHO there is too many transformations. 恕我直言,有太多的转换。

Try simple one: 尝试简单的一个:

WHERE
        mantis_bug_table.date_submitted
    BETWEEN '2014-10-01' AND '2014-12-31' 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM