SQL 在何处过滤嵌套查询
我有一个如下所示的查询:
Insert Into tblX (a,b,c)
Select x as a, y as b
(select top 1 whatever from tblZ as z where z.aID = y.aID order by z.s desc) as c
from tblY as y
where y.foo = 'bar'
AND c <> NULL
问题是最后一行。 它告诉我 c 是无效的列名。也使用 yc 得到相同的结果。 我不需要在巨大的内部查询为空的地方插入行,因为 tblX 不能在那里接受空值。我觉得我应该能够过滤该列,但我无法完全正确地理解语法。
I have a query that looks like this:
Insert Into tblX (a,b,c)
Select x as a, y as b
(select top 1 whatever from tblZ as z where z.aID = y.aID order by z.s desc) as c
from tblY as y
where y.foo = 'bar'
AND c <> NULL
The problem is that last line.
It tells me that c is an invalid column name. using y.c as well, to the same result.
I need to not inset rows where that giant inner query is null, because tblX cannot accept nulls there. I feel like I should be able to filter on that column, but I can't quite get the syntax right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要双重嵌套此查询。
另外,取决于您的 DBMS,但您应该检查
C IS NOT NULL
您正在使用两个没有连接的表。如果您告诉我们您想要实现什么目标,我们可以提供更好的帮助。
You will probably need to double-nest this query.
Also, depends on your DBMS, but you should be checking
C IS NOT NULL
You are using two tables without a join. If you tell us what you are trying to achieve, we can help better.
最终起作用的是双重嵌套查询。
What ended up working is double nesting the query.