首页 > 代码库 > MYSQL join using like and get concat function

MYSQL join using like and get concat function

在项目中,需要多表关联 以及获取一个店下面所有的店员的名称, 需要用到类似SUM的函数  GROUP_CONCAT

关联时条件用LIKE时,需要用到字符串做条件, 用到CONCAT函数


FROM (bst_store AS st
LEFT JOIN bst_user AS charge ON st.uid LIKE CONCAT(‘%,‘,charge.id,‘,%‘)
LEFT JOIN bst_user AS guide ON st.did LIKE CONCAT(‘%,‘,guide.id,‘,%‘)
LEFT JOIN bst_fill_total AS ft ON st.id = ft.sid
)


ft.inputtime,ft.updatetime,
GROUP_CONCAT(charge.name SEPARATOR ‘ ‘) AS charge_name,
GROUP_CONCAT(guide.name SEPARATOR ‘ ‘) AS guide_name


在GROUP_CONCAT中出现重复时需要去重

GROUP_CONCAT(DISTINCT charge.name SEPARATOR ‘ ‘) AS charge_name,
GROUP_CONCAT(DISTINCT guide.name SEPARATOR ‘ ‘) AS guide_name
 

MYSQL join using like and get concat function