Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何从表中获取所需的行_Mysql_Sql Server - Fatal编程技术网

Mysql 如何从表中获取所需的行

Mysql 如何从表中获取所需的行,mysql,sql-server,Mysql,Sql Server,我希望所有的产品id都有网站id=0(零),而没有其他价值。下面是我的表格数据 +------------+------------+ | product_id | website_id | +------------+------------+ | 19112 | 0 | | 19112 | 1 | | 19112 | 2 | | 19113 | 1 | | 19110 |

我希望所有的产品id都有网站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 |
+------------+------------+

谁能帮我查询一下吗。谢谢你

要获得所需的结果,可以使用以下查询

select product_id,website_id
from t
group by product_id
having count(*)=sum(website_id = 0) 

要获得所需的结果,可以使用以下查询

select product_id,website_id
from t
group by product_id
having count(*)=sum(website_id = 0) 

选择产品id、网站id
从表\u名称
按产品编号分组
总和(网站id)<1
更简化的版本。

选择产品id、网站id
从表\u名称
按产品编号分组
总和(网站id)<1
更简化的版本