2 回答

TA貢獻2003條經驗 獲得超2個贊
您需要對adhesives源表中的每一列進行一個連接,如下所示:
SELECT
s.sheet_color,
s.sheet_code,
s.factor_1,
s.factor_2,
sb.brand_name,
a1.match_code match_code_1,
a1.match_name match_name_1,
a2.match_code match_code_2,
a2.match_name match_name_2,
a3.match_code match_code_3,
a3.match_name match_name_3
FROM sheets s
LEFT JOIN sheet_brands sb ON sb.brand_id = s.brand_id
LEFT JOIN adhesives a1 ON a1.adhesive_id = s.adhesive_id_1
LEFT JOIN adhesives a2 ON a2.adhesive_id = s.adhesive_id_2
LEFT JOIN adhesives a3 ON a3.adhesive_id = s.adhesive_id_3

TA貢獻1829條經驗 獲得超6個贊
您必須加入表adhesives兩次才能同時獲得match_codes 和match_names:
SELECT s.sheet_color, s.sheet_code, s.factor_1, s.factor_2,
b.brand_name,
a1.match_code match_code1, a1.match_name match_name1,
a2.match_code match_code2, a2.match_name match_name2
FROM sheets s
LEFT JOIN sheet_brands b ON b.brand_id = s.brand_id
LEFT JOIN adhesives a1 ON a1.adhesive_id = s.adhesive_id_1
LEFT JOIN adhesives a2 ON a2.adhesive_id = s.adhesive_id_2
為表使用別名并使用這些別名限定列名。
如果您還想要并且match_code因為match_name您adhesive_id_3將需要再加入一個:
SELECT s.sheet_color, s.sheet_code, s.factor_1, s.factor_2,
b.brand_name,
a1.match_code match_code1, a1.match_name match_name1,
a2.match_code match_code2, a2.match_name match_name2,
a3.match_code match_code3, a3.match_name match_name3
FROM sheets s
LEFT JOIN sheet_brands b ON b.brand_id = s.brand_id
LEFT JOIN adhesives a1 ON a1.adhesive_id = s.adhesive_id_1
LEFT JOIN adhesives a2 ON a2.adhesive_id = s.adhesive_id_2
LEFT JOIN adhesives a3 ON a3.adhesive_id = s.adhesive_id_3
- 2 回答
- 0 關注
- 143 瀏覽
添加回答
舉報