【发布时间】:2019-03-01 06:04:48
【问题描述】:
我对 SQL 很陌生,非常感谢我正在从事的项目能在这方面提供一些帮助。我正在使用 SQLite,不确定这是否会有所不同!
如果 3 列相同但 1 列不同,我需要编写一个输出一行的查询。
第 2、3 和 4 列的组合必须在另一行中有重复项,
但是
第 1、2、3 和 4 列的组合不得在任何其他行中有任何重复。
示例数据库:
ROW 1 : 12345 | Test1 | Something1 | And1 (I don't want this, it's a full row duplicate with row 2)
ROW 2 : 12345 | Test1 | Something1 | And1 (I don't want this, it's a full row duplicate with row 1)
ROW 3 : 12344 | Test1 | Something1 | And3 (I don't want this, it's not a full row duplicate but col 2, 3 and 4 combined doesn't exist anywhere else in the table)
ROW 4 : 12222 | Test2 | Something1 | And2 (I want this! It's not a full row duplicate and columns 2, 3 and 4 combined exists in row 9)
ROW 5 : 12222 | Test3 | Something1 | And3
ROW 6 : 12222 | Test3 | Something1 | And3
ROW 7 : 12224 | Test3 | Something1 | And3
ROW 8 : 12222 | Test3 | Something2 | And3
ROW 9 : 12000 | Test2 | Something1 | And2
我想要的输出是:
12222 | Test2 | Something1 | And2
12224 | Test3 | Something1 | And3
12000 | Test2 | Something1 | And2
我希望这对某人有意义。提前感谢您的帮助。
【问题讨论】:
-
您的预期输出实际上没有意义。输入表中没有
12222 | Test2 | Something1 | And2记录。 -
到目前为止你尝试了什么?
-
感谢您的评论,我会调整它。
-
@Aldeguer 我已经尝试了太多,无法提及所有内容
-
@TimBiegeleisen 现在我已经改变了它。你想象的输出是我应该放的吗?
标签: sql sqlite duplicates unique