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%?
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. 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'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.