从数据库mysql中提取一对多关系数据

wqsoz72f  于 2023-01-01  发布在  Mysql
关注(0)|答案(1)|浏览(129)

这是我的考勤表

这是我的用户表:

我想在此类型中接受输出:

piah890a

piah890a1#

试试这个:

set @start_date='2022-12-30';
set @end_date='2022-12-31';

WITH recursive Date_Ranges AS (
    select @start_date as date
    union all
    select date + interval 1 day from Date_Ranges
    where date < @end_date
)

SELECT
    new_table.*,
    (
        SELECT
            group_concat(`time`)
        FROM
            `clockin`
        WHERE
            `emid`=new_table.`id` AND
            `date`=new_table.`date`
    ) as `time`
FROM
    (select * from `user` full join Date_Ranges) as new_table
order by date desc

相关问题