我有两张桌子。一个显示工作模式名称,一个显示每天的工作小时数,每列中都有模式 ID。我希望它链接起来,以便每天的时间显示在一行上。对于每个模式,最多有 28 个,因此任何天数较少的模式都应返回 null。我使用了以下内容:
SELECT DISTINCT tn.pat_nm AS 'Pattern Name',
tn.pat_id AS 'Pattern ID',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=1) AS 'Day 1',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=2) AS 'Day 2',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=3) AS 'Day 3',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=4) AS 'Day 4',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=5) AS 'Day 5',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=6) AS 'Day 6',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=7) AS 'Day 7',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=8) AS 'Day 8',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=9) AS 'Day 9',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=10) AS 'Day 10',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=11) AS 'Day 11',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=12) AS 'Day 12',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=13) AS 'Day 13',
(select format(td.pat_day_hrs,'HH:mm') where td.pat_day_no=14) AS 'Day 14'
FROM trentadm.tpat_nm tn
JOIN trentadm.tpat_det td
ON td.pat_id=tn.pat_id
ORDER BY tn.pat_nm
我得到以下结果
有没有办法让每个模式 ID 的所有时间都在一行上?
先感谢您!