假设我有一个复杂的查询,它从大量表中获取数据。
SELECT
DISTINCT
table1.hash,
table2.field1,
table3.field1,
table4.field1,
...
...
...
FROM table1
inner JOIN table2
ON table1.hash=device_model.hash
and table1.date = table2.date
and table1.time = table2.time
...
...
...
inner JOIN table_n-1
ON table1.hash=table_n-1.hash
and table1.date = table_n-1.date
and table1.time = table_n-1.time
left JOIN table_n
ON table1.hash=table_n.hash
and table1.date = table_n.date
and table1.time = table_n.time
...
...
...
ORDER BY table1.date
感谢“DISTINCT”运算符,我得到了三行的结果,例如
+---------+----------+------------+
|value1 |Null | value3 |
+---------+----------+------------+
|value1 |Null | Null |
+---------+----------+------------+
|value1 |value2 | null |
+---------+----------+------------+
|value1 |Null | value3 |
+---------+----------+------------+
所以我每行至少有一个 Null 。如何将选择结果合并为一行以获取所有数据?我想看到类似的东西:
+---------+----------+------------+
|value1 |value2 | value3 |
+---------+----------+------------+
显然,第一行的 value3 等于最后一行的 value3。因此,结果行只是 Null 的不同。