【问题标题】:SQL JOIN returns more number of rows than the original number of rows in tableSQL JOIN 返回的行数比表中的原始行数多
【发布时间】:2021-05-21 08:58:00
【问题描述】:

这可能是一个简单的问题。不幸的是,我无法理解这背后的逻辑。我在 SQL 中创建了 3 个表,即 testfall、testschritte、inhalt 和 case,test_step、kommentar 分别是列。

SELECT cases,test_step,kommentar FROM testschritte JOIN testfall ON testschritte.teil_num = testfall.teil_num JOIN inhalt ON inhalt.indeces = testschritte.indeces

testschritte 中的 test_step 列有 2220 行,testfall 表中的 case 有 9 行。因此,结果计数应该在这些行附近,但我在 JOIN 之后的结果有 45327 行。这怎么可能?如果发生这种情况,会不会数据不正确?

【问题讨论】:

  • 假设 testschritte.teil_num 在 5 行中具有值 abctestfall.teil_num 在 3 行中具有值 abc。当他们加入时,将产生 15 行。如果连接列的值不是不同的,则不应期望它们最多与表(或表)中的行数一样多
  • 谢谢。现在知道了@mangusta

标签: database sqlite better-sqlite3


【解决方案1】:

加入后的结果并不总是等于表输入数据的总和。 这取决于您在每列每行中的条件数据

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-01
    • 1970-01-01
    • 2015-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多