mysql - WHERE/GROUP By Condition - 一个名称但多个值
问题描述
我有下表:
Name Product
Bob Car
Bob Apples
Bob Pears
Bob Car
John Apples
John Pears
无论谁购买了 Product Car,我都想与其他人保持距离。所以,我创建了一个标志:
Name Product Flag
Bob Car 1
Bob Apples 0
Bob Pears 0
Bob Car 1
John Apples 0
John Pears 0
但是我的标志的问题是,即使我做了一个 where 条件并说,告诉我消费者 WHERE 标志!=1,它也会选择 Bob。这是不正确的,因为 Bob 拥有汽车。
我仍然想按产品分组。
如何将上表分成两组?
谢谢!
解决方案
使用以下查询:-
select name from table where flag!=1
and name not in (select name from table where flag = 1)
group by name
推荐阅读
- mysql - Flutter - 将列表转换为 json 并存储在 MYSQL 数据库中
- javascript - 如何使用js更改html中的控制列表?
- excel - 运行时错误 404 范围类的粘贴特殊方法失败
- android - 我的 apk 如何与我的本地服务器通信?
- linux - Ubuntu新用户登录但username@不存在
- tomcat - 在 grails 2.2 中没有任何插件生成的战争文件是 20mb?
- java - 两个原始类型流到一个对流
- amazon-web-services - 导出到浏览器后从 aws acm 下载私有证书显示无效证书
- javascript - 如何让这个alexa技能识别两个意图
- python - Django Rest Framework 如何序列化关系模型?