Mysql 使用Distinct返回重复的值。如何避免这种情况?
查询: 结果:Mysql 使用Distinct返回重复的值。如何避免这种情况?,mysql,sql,Mysql,Sql,查询: 结果: select distinct (Customer) ,CustomerID from history where Customer != '' and Customer LIKE 'Ram%'; 尝试使用MAX和group by Ramer ram100 Raman ra45 Raman ra45 如果您还想查看所有客户ID,请使用 @kurya:customerID也是字符串数据类型。没关系。顺便说一下,更清楚的是,您
select distinct (Customer) ,CustomerID from history where Customer != '' and Customer LIKE 'Ram%';
尝试使用
MAX
和group by
Ramer ram100
Raman ra45
Raman ra45
如果您还想查看所有客户ID,请使用
@kurya:customerID也是字符串数据类型。没关系。顺便说一下,更清楚的是,您可以添加具有所需结果的示例记录。
select Customer, MAX(CustomerID) CustomerID
from history
where Customer != '' AND Customer LIKE 'Ram%'
GROUP BY Customer
select customer, group_concat(distinct customerid)
from history
where Customer != '' and Customer like 'Ram%'
group by customer