将两行结果合并为两列(mysql)

时间:2016-11-08 06:57:01

标签: mysql

这是 file_tbl enter image description here 这是 name_tbl enter image description here

我想要以下结果。 enter image description here

select email, file, name 
from file_tbl as ft 
join name_tble as nt on ft.email = nt.email 
where nt appId = 6

没有给出所需的结果。

如何实现?

1 个答案:

答案 0 :(得分:0)

这将是你可以使用的东西:

SELECT email,GROUP_CONCAT(DISTINCT file SEPARATOR ','),
       name from file_tbl 
       as ft join name_tble 
       as nt on ft.email = nt.email 
WHERE 1 
GROUP BY nt.email