牛客SQL練習第53題

2021-10-24 11:24:37 字數 885 閱讀 5878

按照dept_no進行彙總,屬於同乙個部門的emp_no按照逗號進行連線,結果給出dept_no以及連線出的結果employees

create

table

`dept_emp`

(`emp_no`

int(11)

notnull

,`dept_no`

char(4

)not

null

,`from_date`

date

notnull

,`to_date`

date

notnull

,primary

key(

`emp_no`

,`dept_no`))

;

輸出格式:

dept_no

employees

d001

10001,10002

d002

10006

d003

10005

d004

10003,10004

d005

10007,10008,10010

d006

10009,10010

使用sqlite的聚合函式group_concat(x,y),其中x是要連線的字段,y是連線時用的符號,可省略,預設為逗號。此函式必須與 group by 配合使用。

select dept_no,group_concat(emp_no,

",")

as employees

from dept_emp

group

by dept_no

牛客SQL練習第57題

使用含有關鍵字exists查詢未分配具體部門的員工的所有資訊。create table employees emp no int 11 notnull birth date date notnull first name varchar 14 not null last name varchar 1...

牛客SQL練習第60題

按照salary的累計和running total,其中running total為前n個當前 to date 9999 01 01 員工的salary累計和,其他以此類推。具體結果如下demo展示。create table salaries emp no int 11 notnull salary...

牛客SQL練習第68題

牛客每天有很多人登入,請你統計一下牛客每個使用者最近登入是哪一天,用的是什麼裝置.有乙個登入 login 記錄表,簡況如下 第1行表示id為2的使用者在2020 10 12使用了客戶端id為1的裝置登入了牛客網 第4行表示id為3的使用者在2020 10 13使用了客戶端id為2的裝置登入了牛客網 ...