- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 2 个查找表和 1 个相交表,例如:
thing thing_feature feature
+----+-------------+ +----+----------+------------+ +----+-------------+
| id | name | | id | thing_id | feature_id | | id | name |
+----+-------------+ +----+----------+------------+ +----+-------------+
| 1 | Thing One | | 1 | 1 | 1 | | 1 | Feature A |
| 2 | Thing Two | | 2 | 2 | 1 | | 2 | Feature B |
| 3 | Thing Three | | 3 | 2 | 2 | | 3 | Feature C |
| 4 | Thing Four | | 4 | 3 | 3 | | 4 | Feature D |
+----+-------------+ +----+----------+------------+ +----+-------------+
我不知道要生成的查询...
"Thing One", "Feature A"
"Thing Two", "Feature A"
"Thing Two", "Feature B"
"Thing Three", "Feature C"
"Thing Four", null
如果我停在相交表上,我可以让它包含“Thing 4”...
select
thing.name,
tf.id
from
thing
left outer join thing_feature tf on thing.id = tf.thing_id;
"Thing One", 1
"Thing Two", 1
"Thing Two", 2
"Thing Three", 3
"Thing Four", null
...但我无法弄清楚通过 thing_feature.feature_id 使查询“加入备份”到特征表的语法。我几乎要处理的查询丢失了无特征的“第四件事”。
select
thing.id,
thing.name,
tf.id,
feature.name
from
thing
left outer join thing_feature tf on thing.id = tf.thing_id,
feature
where
tf.feature_id = feature.id;
"Thing One", 1, "Feature 1"
"Thing Two", 1, "Feature 1"
"Thing Two", 2, "Feature 2"
"Thing Three", 3, "Feature 3"
也许是我深入 NoSQL 太久了。如果重要的话,这就是 MySQL。
这里没什么帮助?我需要对查询执行哪些操作才能包含“第四项”行?
最佳答案
你差不多了。您只需要再执行一次左外连接,以确保将所有结果保留在左表中,并在右表中获取所有空值。
select
thing.name,
f.name
from
thing
left outer join thing_feature tf on thing.id = tf.thing_id
left outer join feature f on tf.feature_id = f.id;
关于mysql - 无法让 LEFT OUTER JOIN 通过相交表工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32729943/
class Outer { class Inner { } } public class Demo { public static void main(
不确定我是否明白这一点,但我从 pyLint 收到验证错误说: Redefining name 'a' from outer scope (line 443) (redefined-outer-nam
我是 SQL 新手,最近开始在我的代码中实现联接,我希望检索的数据可以使用以下 SQL 语句来完成。但是,如您所知,SQLite3 不支持 RIGHT OUTER 和 FULL OUTER JOIN。
怀疑但不确定:是 FROM 中表格的简单列表-clause 根据定义是完全连接? SELECT * FROM table1, table2 我们在参数不相等的情况下连接表的情况是否是完全外连接的实现?
我想知道 numpy 中是否有一个功能与 np.outer 类似,但使用二维数组和向量作为输入参数。结果应该是一个 3 维数组。 例如,如果我有一个矩阵 M 和一个向量 v,我想将原始矩阵 M 堆叠
以下代码在 MSVC 上编译: #include class Bob { int a; friend class Outer; }; class Outer {
Spark SQL 文档指定 join()支持以下连接类型: Must be one of: inner, cross, outer, full, full_outer, left, left_out
谁能帮我解决以下问题.. 这里我们有1.左外连接2.两个右外连接 如何结合左右 O.J 并创建与上面相同的效果, 我需要重写相同的查询,这是因为我正在将旧的 ms SQL2009 转换为 ms SQL
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
使用 ANSI 语法的 Informix 查询性能是否有差异: SELECT .. LEFT OUTER JOIN some_table ON () LEFT OUTER JOIN some_
根据clang , gcc 和 vs2013,函数 Outer::f 是 not 类 Outer::Inner 的 friend 。 struct Outer { void f() {}
换句话说,对于嵌套/多个 JOIN SQL 语句,是否应该始终首先使用 INNER JOIN(要么将其放在顶部行或通过使用括号首先 INNER JOIN 两个表)并确保它在任何 OUTER JOIN
我们有以下查询。使用 LEFT OUTER 连接需要 9 秒才能执行。将 LEFT OUTER 更改为 LEFT INNER 可将执行时间减少到 2 秒,并且返回相同行数。由于无论连接类型如何,都正在
为什么在实例化通用外部类(连同内部类)时使用菱形运算符会在代码段 2 中产生错误,而代码段 1 却完全没问题? 我知道稀有类型是被禁止的,但我的情况不是稀有类型——在稀有类型中,外部和内部都是通用的,
我有 4 个表,如下所示。 表:类 ClassID | ClassSTD -------------------------------- 1 | STD-1 2
是否有关于“外部 =>”功能的文档?它看起来像一个带有推断类型的自类型注释。然而我有一种感觉,我错了。 如果是这样,是否只是表达对 super 的访问的不同方式? ? trait A extends
我有 2 个表 users 和 orders,我想获取 users 和他的订单数 SELECT `users`.*, `orders`.*,count(*) FROM `users` LEFT JOI
我有一个非常古老的 informix 过程,我想在我的新 PostgreSQL 数据库中使用它。我是 Postgres 的新手,我觉得连接很不一样。 这是我的旧 Informix 代码的一部分: CR
我非常擅长 SQL 语句,希望能得到一点帮助。我发现我需要对其中一些表使用 OUTER 联接,但 MySQL 没有该功能。 SELECT validclick.Campaign
对,这有点令人困惑,我不确定通过 sql 是否可行。 我的第一个表叫做成员,我目前有这个 user:ID type: firstname: lastname: 这是表中的数据 members tabl
我是一名优秀的程序员,十分优秀!