如何組合兩個SQL表的數據後,結果輸出到HTML表的方式有問題。如該表所示如何在JOIN後合併行中出現重複的第一列但其他列中的信息不同
表1顯示如下
+-------------+------------+---------+
| StationName | Address | Manager |
+-------------+------------+---------+
| Station1 | London | John |
| Station2 | Liverpool | Phil |
| Station3 | Manchester | Mike |
+-------------+------------+---------+
表2顯示如下
+-------------+--------+--------+--------+
| StationName | Score1 | Score2 | Score3 |
+-------------+--------+--------+--------+
| Station1 | Pass | | |
| Station1 | | Fail | |
| Station1 | | | Pass |
| Station2 | Fail | | |
| Station2 | | Pass | |
| Station2 | | | Pass |
| Station3 | Pass | | |
| Station3 | | Pass | |
| Station3 | | | Pass |
+-------------+--------+--------+--------+
我想組合的數據以輸出
+-------------+------------+---------+--------+--------+--------+
| StationName | Address | Manager | Score1 | Score2 | Score3 |
+-------------+------------+---------+--------+--------+--------+
| Station1 | London | John | Pass | Fail | Pass |
| Station2 | Liverpool | Phil | Fail | Pass | Pass |
| Station3 | Manchester | Mike | Pass | Pass | Pass |
+-------------+------------+---------+--------+--------+--------+
然而,它像這樣出現。
+-------------+------------+---------+--------+--------+--------+
| StationName | Address | Manager | Score1 | Score2 | Score3 |
+-------------+------------+---------+--------+--------+--------+
| Station1 | London | John | Pass | | |
| Station1 | London | John | | Fail | |
| Station1 | London | John | | | Pass |
| Station2 | Liverpool | Phil | Fail | | |
| Station2 | Liverpool | Phil | | Pass | |
| Station2 | Liverpool | Phil | | | Pass |
| Station3 | Manchester | Mike | Pass | | |
| Station3 | Manchester | Mike | | Pass | |
| Station3 | Manchester | Mike | | | Pass |
+-------------+------------+---------+--------+--------+--------+
我的查詢是:
SELECT *
FROM table1
LEFT JOIN table2
ON table1.stationName = table2.stationName
我想我正在尋找使用類似於GROUP BY的東西的一種方式,但是沒有它彙總數據。
有人建議透視表,雖然從我看過的那些,它們是有用的計算 - 我感興趣的文本數據組合成多個表,其中共同的環節是站名的列。
任何人都可以請告知如何實現這一目標?
我到底到了那裏,但這個偉大的工程。謝謝 – misterpauly