mysql的GROUP CONCAT函式的用法

2021-07-04 16:25:28 字數 501 閱讀 3190

當我們想查詢某個資料中所屬的多個分類時,並且想讓這多個分類顯示成一組的話,那麼就用到了函式group_concat。下面是個例子:

select *,(select group_concat(sys.type_name) from sys_type sys where sys.type_id in( select type_id from type_resource where v_id=1)) as typename,

(select group_concat(per.rc_name) from person_type as per where rc_id in (select rc_id from type_resource where v_id=1)) as rcname from video where v_id=1;

結果為除了查出video表中id為1的所有字段資料之外,還查出了關於sys_type表中的typename,單數typename這會就不止是乙個資料,而是關於video中的id為1的這個所有資料,以逗號隔開。

Mysql分組資料合併group concat用法

group concat用法 預設用法 select group concat vaccine name as do accinename from t vaccine where id in select vaccine id from t dog vaccine where dog id 1 1...

MySQL 多行資料合併 GROUP CONCAT

表結構及資料 drop table if exists course create table course id int 11 not null,name varchar 50 default null comment 姓名 course name varchar 50 default null ...

MySQL 多行資料合併 GROUP CONCAT

表結構及資料 drop table if exists course create table course name varchar 255 character set utf8 collate utf8 general ci default null,course name varchar 25...