1
私は5つのテーブルtb1、tb2、tb3、tb4とtb5を持っています。右のJOINと選択結果
この選択クエリ
SELECT c.COL1, f.COL2, SUM(a.colx1* l.clox2) AS COL3
FROM tb1 c
JOIN tb2 b ON (c.id = b.idC)
JOIN tb3 l ON (b.id = l.idB)
JOIN tb4 a ON (a.id = l.idA)
JOIN tb5 f ON (f.id = a.idF)
GROUP BY c.COL1, f.COL2
この選択クエリの結果
+-----------+-------+-----------+
| COL1 | COL2 | COL3 |
+-----------+-------+-----------+
| project1 | FAM1 | 1250.251 |
| project1 | FAM2 | 2145.325 |
| project2 | FAM1 | 2146.152 |
| project3 | FAM2 | 1248.002 |
| project4 | FAM1 | 3201.684 |
| project4 | FAM2 | 7325.981 |
| project5 | FAM1 | 4657.684 |
しかし、私はprojectxがFAMx
+-----------+-------+-----------+
| COL1 | COL2 | COL3 |
+-----------+-------+-----------+
| project1 | FAM1 | 1250.251 |
| project1 | FAM2 | 2145.325 |
| project2 | FAM1 | 2146.152 |
| project2 | FAM2 | NULL |
| project3 | FAM2 | NULL |
| project3 | FAM2 | 1248.002 |
| project4 | FAM1 | 3201.684 |
| project4 | FAM2 | 7325.981 |
| project5 | FAM1 | 4657.684 |
| project5 | FAM1 | NULL |
を持っていない場合は、この形式で結果を表示したいです
これは私のテストRIGHT JOIN
で動作しません!私は何が欠けていますか?
CREATE TEMPORARY TABLE tempt AS
SELECT c.COL1, f.COL2, SUM(a.colx1* l.clox2) AS COL3
FROM tb1 c
JOIN tb2 b ON (c.id = b.idC)
JOIN tb3 l ON (b.id = l.idB)
JOIN tb4 a ON (a.id = l.idA)
JOIN tb5 f ON (f.id = a.idF)
GROUP BY c.COL1, f.COL2;
SELECT t.* FROM tempt t RIGHT JOIN tb5 f ON (f.COL2 = t.COL2)
tab5テーブルの構造
+----+--------+------+
| id | COL1 | COL2 |
+----+--------+------+
|1 | F1 | FAM1 |
|2 | F2 | FAM2 |
+----+--------+------+
を'RIGHT JOIN'? – axiac
SELECT t。* FROM tempt t右ジョイントtb5 f ON(f.COL2 = f.COL2) – isom
'ON(f.COL2 = f.COL2)'?たぶん 'ON(t.COL2 = f.COL2)' ... – axiac