Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.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
Sql查询错误,应仅返回在其他表中存在一次的供应商_Sql_Having - Fatal编程技术网

Sql查询错误,应仅返回在其他表中存在一次的供应商

Sql查询错误,应仅返回在其他表中存在一次的供应商,sql,having,Sql,Having,如果我尝试执行它,我会出错: create View vwEinzellieferant as Select P.SupplierID, S.CompanyName, S.ContactName, S.Address + ' ' + S.City + ' ' + S.Region + ' ' + S.PostalCode + ' ' + S.Country, S.Phone from Suppliers S inner join Products P on S.SupplierID = P.Su

如果我尝试执行它,我会出错:

create View vwEinzellieferant
as
Select P.SupplierID, S.CompanyName, S.ContactName, S.Address + ' ' + S.City + ' ' + S.Region + ' ' + S.PostalCode + ' ' + S.Country, S.Phone
from Suppliers S inner join Products P on S.SupplierID = P.SupplierID
group by P.SupplierID, S.CompanyName, S.ContactName, S.Address, S.City, S.Region, S.PostalCode, S.Country, S.Phone
having (Count(S.SupplierID in (Select SupplierID from Products))) > 2;
在有一个问题,但我不知道是什么。 说明:查询应创建一个视图,但仅针对产品列表中的供应商。
有人能帮我吗?

似乎您需要重新排列
HAVING
子句,以便返回相关的
COUNT
值等于
1
,例如

SELECT P.SupplierID,
       S.CompanyName,
       S.ContactName,
       S.Address + ' ' + S.City + ' ' + S.Region + ' ' + S.PostalCode + ' ' +
       S.Country,
       S.Phone
  FROM Suppliers S
  JOIN Products P
    ON S.SupplierID = P.SupplierID
 GROUP BY P.SupplierID,
          S.CompanyName,
          S.ContactName,
          S.Address,
          S.City,
          S.Region,
          S.PostalCode,
          S.Country,
          S.Phone
 HAVING ( SELECT COUNT(*) FROM Products WHERE SupplierID = S.ID ) = 1 

什么是错误?在Havigi结尾的中间括号上的错误语法,是的,语句没有多大意义。你想做什么?我想得到其他表中只有一次的所有供应商,所以我试图得到表中不超过一次的所有供应商ID用你正在使用的数据库标记你的问题。