61 Star 425 Fork 144

xuthus / 数据库SQL实战

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
53.按照dept_no进行汇总.md 503 Bytes
一键复制 编辑 原始数据 按行查看 历史
xuthus 提交于 2019-08-12 23:23 . add:all

按照dept_no进行汇总

题目描述

按照dept_no进行汇总,属于同一个部门的emp_no按照逗号进行连接,结果给出dept_no以及连接出的结果employees

CREATE TABLE `dept_emp` (
`emp_no` int(11) NOT NULL,
`dept_no` char(4) NOT NULL,
`from_date` date NOT NULL,
`to_date` date NOT NULL,
PRIMARY KEY (`emp_no`,`dept_no`));

答案

select dept_no,group_concat(emp_no) from dept_emp group by dept_no

题解

聚合函数group_concat的使用

SQL
1
https://gitee.com/xuthus5/Database-SQL-Actual-Combat.git
git@gitee.com:xuthus5/Database-SQL-Actual-Combat.git
xuthus5
Database-SQL-Actual-Combat
数据库SQL实战
master

搜索帮助