选择列表中只能指定一个表达式

发布于 2024-11-08 16:18:50 字数 1347 浏览 0 评论 0原文

我需要让这个 sql 查询正常工作:

SELECT     TOP 15 id, thumb, width, height
FROM         (SELECT     vPictures.id, vPictures.thumb, vPictureCrops.width, vPictureCrops.height
                       FROM          vPictures INNER JOIN
                                              vPictureCrops ON vPictures.id = vPictureCrops.picid
                       WHERE      (vPictureCrops.width = '602') AND (vPictureCrops.height = '131')
                       GROUP BY vPictures.id, vPictures.thumb, vPictureCrops.width, vPictureCrops.height) AS derivedtbl_1
WHERE     (id NOT IN
                          (SELECT     TOP 0 vPictures_1.id, vPictures_1.datetime, vPictures_1.url, vPictures_1.author, vPictures_1.companyID, vPictures_1.source, 
                                                   vPictures_1.people, vPictures_1.text, vPictures_1.thumb, vPictures_1.logo, vPictureCrops_1.id AS Expr1, vPictureCrops_1.picid, 
                                                   vPictureCrops_1.url AS Expr2, vPictureCrops_1.width, vPictureCrops_1.height
                            FROM          vPictures AS vPictures_1 INNER JOIN
                                                   vPictureCrops AS vPictureCrops_1 ON vPictures_1.id = vPictureCrops_1.picid))
ORDER BY id DESC

你能帮我吗?

错误信息: “当子查询不带 EXISTS 引入时,选择列表中只能指定一个表达式)”

I need to get this sql query working:

SELECT     TOP 15 id, thumb, width, height
FROM         (SELECT     vPictures.id, vPictures.thumb, vPictureCrops.width, vPictureCrops.height
                       FROM          vPictures INNER JOIN
                                              vPictureCrops ON vPictures.id = vPictureCrops.picid
                       WHERE      (vPictureCrops.width = '602') AND (vPictureCrops.height = '131')
                       GROUP BY vPictures.id, vPictures.thumb, vPictureCrops.width, vPictureCrops.height) AS derivedtbl_1
WHERE     (id NOT IN
                          (SELECT     TOP 0 vPictures_1.id, vPictures_1.datetime, vPictures_1.url, vPictures_1.author, vPictures_1.companyID, vPictures_1.source, 
                                                   vPictures_1.people, vPictures_1.text, vPictures_1.thumb, vPictures_1.logo, vPictureCrops_1.id AS Expr1, vPictureCrops_1.picid, 
                                                   vPictureCrops_1.url AS Expr2, vPictureCrops_1.width, vPictureCrops_1.height
                            FROM          vPictures AS vPictures_1 INNER JOIN
                                                   vPictureCrops AS vPictureCrops_1 ON vPictures_1.id = vPictureCrops_1.picid))
ORDER BY id DESC

Can you help me?

The error message:
"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS)"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失与倦" 2024-11-15 16:18:50

Where (ID not IN(

选择必须只有一个字段,IN 无法理解您要解析的列。

例如来自 here

USE AdventureWorks2008R2;
GO
SELECT p.FirstName, p.LastName
FROM Person.Person AS p
    JOIN Sales.SalesPerson AS sp
    ON p.BusinessEntityID = sp.BusinessEntityID
WHERE p.BusinessEntityID IN
   (SELECT BusinessEntityID
   FROM Sales.SalesPerson
   WHERE SalesQuota > 250000);
GO

无论如何,不​​确定您想通过查询实现什么目的,您能否解释一下 where in 子句的用法,

The Where (ID not IN(

The Select must only have one field are the IN can not understand which column you are trying to parse.

Eg from here

USE AdventureWorks2008R2;
GO
SELECT p.FirstName, p.LastName
FROM Person.Person AS p
    JOIN Sales.SalesPerson AS sp
    ON p.BusinessEntityID = sp.BusinessEntityID
WHERE p.BusinessEntityID IN
   (SELECT BusinessEntityID
   FROM Sales.SalesPerson
   WHERE SalesQuota > 250000);
GO

Not sure what you are trying to achieve with the query anyway, can you explain the usage of the where in clause,

一杆小烟枪 2024-11-15 16:18:50

我可以看到 (id NOT IN (SELECT TOP 0 vPictures_1.id, ...

  1. 仅当应在 IN 之后的 select 语句中指定列时出现 两个问题例如 (id NOT IN (SELECT vPictures_1.id FROM ...

    )

  2. 即使您将其设为一个字段 vPictures_1.id,由于 top 0,条件也将始终为 false。

I can see two problems with (id NOT IN (SELECT TOP 0 vPictures_1.id, ...

  1. only when column should be specified in the select statement after IN. For example (id NOT IN (SELECT vPictures_1.id FROM ...

  2. even if you make it just one field vPictures_1.id the condition will always be false because of top 0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文