0

我将如何编写一个不会使用 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' 
  AND DATEDIFF(CURDATE(), edited_date) between 2 and 3 
order by 1;

第二个查询是:

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<DATE_SUB(now(),interval 48 hour) 
order by 1;

我该如何过滤它?

4

1 回答 1

0

尝试 GROUP BY

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 DATEDIFF(CURDATE(), edited_date) between 2 and 3
 GROUP BY ord_no,name, mobile, address,  rate, mrp,
   create_date, edited_date,status 
order by 1;

你能指定它是否是你想要唯一的某个字段吗?否则这应该工作。

于 2013-10-23T07:26:11.617 回答