场景:
表A(商户表MERCHANT):
ID | MERCHANT_NAME | WX_NATIVE | WX_JSAPI | ALI_NATIVE |
1 | 第一个商户 | 1 | 2 | 2 |
2 | 第二个商户 | 1 | 1 | 2 |
表B(通道表CHANNEL):
ID | CHANNEL_NAME |
1 | 官方 |
2 | 其他通道 |
需要展示的效果:
第一个商户 官方 其他通道 其他通道
第二个商户 官方 官方 其他通道
SELECT
me.`id`,
me.`merchant_name`,
c1.`channel_name`,
c2.`channel_name`,
c3.`channel_name`
FROM
MERCHANT AS me
LEFT JOIN CHANNEL AS c1
ON me.`wx_native` = c1.`id`
LEFT JOIN CHANNEL AS c2
ON me.`ali_native` = c2.`id`
LEFT JOIN CHANNEL AS c3
ON me.`wx_jsapi` = c3.`id`