[英]Select records only if all matching records are same value
I have the following table:我有下表:
id ![]() |
food![]() |
type![]() |
nutrition![]() |
---|---|---|---|
1 ![]() |
chicken![]() |
meat![]() |
healthy![]() |
2 ![]() |
salad![]() |
vegetable![]() |
healthy![]() |
3 ![]() |
burger![]() |
meat![]() |
unhealthy![]() |
I want to query all types of food which are completely healthy.我想查询完全健康的所有类型的食物。 The expected result here is only vegetable because burger is considered unhealthy even if chicken is healthy.
这里的预期结果只是蔬菜,因为即使鸡肉是健康的,汉堡也被认为是不健康的。
In MySQL or Postgres, we can try aggregating:在 MySQL 或 Postgres 中,我们可以尝试聚合:
SELECT type
FROM yourTable
GROUP BY type
HAVING SUM(nutrition <> 'healthy') = 0;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.