在mysql查询中添加一个条件

时间:2013-10-23 06:35:10

标签: mysql

SELECT ord_no,name, mobile, address,  rate, mrp, create_date, edited_date,status 
FROM orders o, customer c
where o.cust_id = c.id and status = 'CHECKED' order by 1;

我想将此条件添加到上述查询

edited_date < DATE_SUB(now(), interval 48 hour)

我该怎么做?

2 个答案:

答案 0 :(得分:0)

SELECT ord_no,name, mobile, address,  rate, mrp, create_date, edited_date, status 
FROM orders o, customer c
where o.cust_id = c.id 
and status = 'CHECKED' 
and edited_date < now() - interval 48 hour

答案 1 :(得分:0)

如果要加入两个表,请使用JOIN运算符。

为什么不添加所需的WHERE子句?必须在ORDER BY

之前插入
SELECT ord_no, name, mobile, address,  rate, mrp, create_date, edited_date, status 
FROM orders o
    INNER JOIN customer c
        ON o.cust_id = c.id
WHERE status = 'CHECKED' 
AND edited_date < DATE_SUB(now(),interval 48 hour)
ORDER BY 1