說,還有2個表:在SQL中列舉枚舉?
Person
| id | name |
LanguagesSpoken
| person_id | language_name |
有沒有一種方法來創建將包含2列的觀點:person_name
和languages_spoken
作爲一個逗號分隔的列表?
我正在開發針對SQLite。
說,還有2個表:在SQL中列舉枚舉?
Person
| id | name |
LanguagesSpoken
| person_id | language_name |
有沒有一種方法來創建將包含2列的觀點:person_name
和languages_spoken
作爲一個逗號分隔的列表?
我正在開發針對SQLite。
用途:
SELECT p.name,
GROUP_CONCAT(ls.language_name, ',')
FROM PERSON p
JOIN LANGUAGESSPOKEN ls ON ls.personid = p.personid
GROUP BY p.name
select name, group_concat(language_name) as languages
from person p inner join languagesSpoken l
on p.id = l.person_id
group by l.person.id
GROUP_CONCAT()是你的答案。