使用timestamp的mysql日期比较返回错误的答案

时间:2015-02-19 21:42:55

标签: mysql sql phpmyadmin

我正在尝试使用2015年2月2日之间的日期从MySQL获取数据,从使用此查询开始结束,但MySQL在2月返回所有行

SELECT CustomerID, 
    CustomerName, 
    DATE, 
    Doller,
    Minute ,
    Rate,Total, 
    NULL AS Amountofpaying
FROM saletrack where CustomerID=1
UNION ALL 
SELECT CustomerID, 
    CustomerName, 
    DATE, 
    NULL AS Doller,
    NULL AS Minute, 
    NULL AS Rate, 
    NULL AS Total, 
    Amountofpaying
FROM paymentdetails 
where CustomerID=1 and  `date` BETWEEN '2015-02-02 00:00:01' AND '2015-02-02 23:59:59'
ORDER BY DATE

请查看我在下面评论过的图片

1 个答案:

答案 0 :(得分:1)

在Sale from saletrack中添加时间戳条件:

SELECT CustomerID, 
    CustomerName, 
    DATE, 
    Doller,
    Minute ,
    Rate,Total, 
    NULL AS Amountofpaying
FROM saletrack where CustomerID=1 and `date` BETWEEN '2015-02-02 00:00:01' AND '2015-02-02 23:59:59'
UNION ALL 
SELECT CustomerID, 
    CustomerName, 
    DATE, 
    NULL AS Doller,
    NULL AS Minute, 
    NULL AS Rate, 
    NULL AS Total, 
    Amountofpaying
FROM paymentdetails 
where CustomerID=1 and  `date` BETWEEN '2015-02-02 00:00:01' AND '2015-02-02 23:59:59'
ORDER BY DATE