我希望所有product_id都有website_id = 0(零)且没有其他值。以下是我的表格数据
+------------+------------+
| product_id | website_id |
+------------+------------+
| 19112 | 0 |
| 19112 | 1 |
| 19112 | 2 |
| 19113 | 1 |
| 19110 | 0 |
| 19110 | 2 |
| 19114 | 0 |
| 19115 | 0 |
| 19115 | 1 |
| 19116 | 0 |
+------------+------------+
我希望从上表数据中跟随行;
+------------+------------+
| product_id | website_id |
+------------+------------+
| 19114 | 0 |
| 19116 | 0 |
+------------+------------+
任何人都可以帮我查询。谢谢!。
答案 0 :(得分:7)
要获得所需的结果,您可以使用以下查询
select product_id,website_id
from t
group by product_id
having count(*)=sum(website_id = 0)
答案 1 :(得分:0)
select product_id,website_id
from table_name
group by product_id
having sum(website_id) < 1
更多简化版。