gpt4 book ai didi

mysql - 关于表过滤的查询,需要一张没有重复的表

转载 作者:行者123 更新时间:2023-11-30 01:09:46 24 4
gpt4 key购买 nike

如何使用 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;

如何过滤它?

最佳答案

尝试分组依据

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;

您能否指定您是否希望某个字段是唯一的?否则这应该有效。

关于mysql - 关于表过滤的查询,需要一张没有重复的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19535227/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com