问题标签 [not-exists]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
8127 浏览

tsql - SQL 的语法不在列表中?

我正在尝试开发一个 T-SQL 查询来排除另一个表“B”中的所有行。这个另一个表“B”有 3 列,包括它的 PK,总共 136 行。所以我想选择表“A”中的所有列减去表“B”中的列。我该怎么做呢?我认为这个查询不正确,因为我仍然收到重复记录错误:

0 投票
2 回答
988 浏览

ruby-on-rails - rails 检查现有实例属性

我在一个社交网站上工作(老实说,基本上是一个 facebook 的副本......),我重用了 insoshi 的大部分内容。但是 insoshi 的供稿对我的喜好不够准确。因为它不支持更专业的消息。您将在以下代码中看到我的意思:

我有不同类型的物品。通常项目有一个“用户”和一个“联系人”。除了帖子,它们还有一个“用户”和一个“所有者”。因为帖子的其他人可以将其写在某人的墙上(因此为所有者)。

现在,当我尝试将联系人设置为 item.contact 时,问题就出现了......它只是不断地用“NoMethod”错误来困扰我,说 item.contact 不存在。(如果该项目是帖子而不是“连接”或类似项目,则这一点很明显)。

所以我征求你的意见:1)用更多的红宝石解决问题,或者2)改变帖子模型,让帖子有一个“用户”和一个“联系人”?

谢谢大家斯特凡诺

0 投票
2 回答
1663 浏览

sql - SQL:检查表是否在特定列中不包含空值

我正在处理一个存储过程,有一次我想检查我的表变量,看看是否有特定字段等于空的零行。换句话说,对于我表中的每一行,该字段都有一个非空值。我不想通过检查 count() 来做到这一点,而是通过使用 EXISTS。

目前我正在这样做:

现在我知道我可以使用 NOT EXISTS,但我认为 NOT EXISTS 比 EXISTS 慢得多。我发誓我最近读过一些东西(我认为是这样),其中有一个例子,说明如何用一个 Exists 子句做我想做的事情,但我找不到它并且忽略了为它添加书签。虽然也许我错了。

我设置 if/else 的原因是因为据我了解 EXISTS 将在 NOT EXISTS 之前返回,并且由于这是一个非常密集的存储过程(非常频繁地调用,有时是批量调用),我希望在这里节省一些处理。

也许我认为这一切都是错误的,或者假设某些事情不正确。我是来学习的,所以如果我错了,请指出我正确的方向。

编辑:显然在这种情况下没有区别(不是 where 子句/子查询的一部分)。但是假设我在 where 子句中使用了存在,并且想要检查上面的确切情况(字段中的所有非空值),特别是当有问题的表可能有数千行时。[对 SO 有点陌生,如果我应该将此作为自己的问题发布,请告诉我]

0 投票
3 回答
262 浏览

mysql - 这个查询是什么意思

这个查询是什么意思

我的理解是:它从表所有者返回 fname 和 lname,而这些名称在表训练器中不存在?我对吗?

0 投票
3 回答
2046 浏览

sql - The purpose of SQL's EXISTS and NOT EXISTS

Every now and then I see these being used, but it never seems to be anything that can't be performed as equally well, if not better, by using a normal join or subquery.

I see them as being misleading (they're arguably harder to accurately visualize compared to conventional joins and subqueries), often misunderstood (e.g. using SELECT * will behave the same as SELECT 1 in the EXISTS/NOT EXISTS subquery), and from my limited experience, slower to execute.

Can someone describe and/or provide me an example where they are best suited or where there is no option other than to use them? Note that since their execution and performance are likely platform dependent, I'm particularly interested in their use in MySQL.

0 投票
2 回答
30793 浏览

mysql - mysql:如果表B中不存在,则从表A中选择所有项目

我在从表 a (id, room_name) 中选择值时遇到问题,其中表 b (room_id, room_start, room_finish) 中没有相应的事件

我的查询如下

表 a 包含多个房间,表 b 包含房间事件 如果时间戳内的任何房间有任何事件,我没有得到任何结果。我希望所有房间都没有活动。

0 投票
4 回答
48942 浏览

sql - 如何在不存在的地方进行插入?

我想将插入查询与“不存在的地方”结合起来,以免违反 PK 约束。但是,如下所示的语法给了我一个Incorrect syntax near the keyword 'WHERE'错误 -

我怎样才能做到这一点?

(一般来说,您可以将插入与 where 子句结合起来吗?)

0 投票
2 回答
277 浏览

mysql - 如果主键值之一不匹配,则 MySQL INSERT

我想做这样的MySQL查询:

让我们试试例子:

结果在这里:

p>

你希望得到这样的结果:

是否可以进行此查询?我正在使用大量数据和过程,例如 加载->比较->保存是不可能的。谢谢!

0 投票
1 回答
2871 浏览

mysql - MySql 5.1.32: call another procedure within a stored procedure and set variable

I'm new at creating and working with stored procedures.

After spending several hours on trying, reading tutorials (and yes reading all the related questions at stackoverflow :-) ) I'm stuck.

This works fine:

When called like:

It gives the proper response: "2"

So far so good. So let's get that into another procedure: (GetOS does the same thing, left out tot minimize reading :-)

When called with

I get the answer "3" (proper response from GetOS), then the procedure stops and does not insert anything.

After installing Toad I saw the reason: an error: "FUNCTION GetAgent does not exist" Well, it is not a function, it's a procedure.

So basicly, my question: How do I call another procedure within a stored procedure and set a variable with the result?

0 投票
2 回答
1758 浏览

asp.net - 在实体框架中使用不存在连接的视图

我需要在 SQL Server 中创建一个视图并GridView在我的.aspx页面上使用它。该视图通过实体框架映射到我的应用程序中。

这是我的例子:

User和表之间的关系UsersInRoles是一对多的。

我需要能够AdminRole在我的 ASP.NET 应用程序中传递值。

我不能在视图中使用参数(即@Role不允许使用)。

只有视图和表可以绑定到GridView一个存储过程(参数可以是一个选项)在这里不好。

有没有一种解决方法来使用 a LEFT OUTER JOINMaybe 而不是NOT EXISTS?这样,JOIN在表上有一个,我可以通过我的应用程序中的实体框架UsersInRoles映射字段,我可以在那里添加条件(with子句)。UsersInRolesEntityDataSource.Where