Mysql SQL-仅选择一种特定类型

Mysql SQL-仅选择一种特定类型,mysql,sql,Mysql,Sql,我想知道是否可以用一个精确的语句选择数据 假设我的数据库中有两个客户,两个客户的值均为1,但其中一个客户的值也为2 只有1号客户我如何才能得到结果?我有兴趣得到所有只有值1的客户,而不是1、2、3等 更具体的说明: **Customer 1:** Name: "Peter" Value: "1" **Customer 2:** Name: "Chris" Value: "1", "2", "3" 现在,我只想得到客户1的结果,客户1的值为1,您可以使用该值,但不存在: 您可以将GROUP B

我想知道是否可以用一个精确的语句选择数据

假设我的数据库中有两个客户,两个客户的值均为1,但其中一个客户的值也为2

只有1号客户我如何才能得到结果?我有兴趣得到所有只有值1的客户,而不是1、2、3等

更具体的说明:

**Customer 1:**
Name: "Peter"
Value: "1"

**Customer 2:**
Name: "Chris"
Value: "1", "2", "3"
现在,我只想得到客户1的结果,客户1的值为1,您可以使用该值,但不存在:

您可以将GROUP BY与COUNT一起使用,例如:

select t.*
from t
where t.value = 1 and 
      not exists (select 1 from t t2 where t2.name = t.name and t2.value <> 1);
SELECT Name
FROM customer
WHERE Value = "1"
GROUP BY Name
HAVING COUNT(DISTINCT(Value)) = 1;