select t.id, t.organization_id, t.name, t.id_card, t.sex, t.birthday, t.phone, t.introduction, t.subject_id, t.position_type, t.ntce_no, t.status, t.check_status, t.remark, o.name as organization_name, si.name as subject_name, t.create_time from t_teacher_info t join t_organization_info o on o.id = t.organization_id join sys_user su on o.id = su.organization_id join sys_dept sd on sd.dept_id = su.dept_id left join t_teacher_subject ts on ts.teacher_id=t.id left join t_subject_info si on si.id = ts.subject_id 这是oracle数据库 如何对si.name 加wm_concat函数
时间: 2024-02-14 10:26:25 浏览: 103
对于Oracle数据库中的si.name字段使用wm_concat函数,你可以按照以下方式修改你的查询语句:
```sql
SELECT
t.id,
t.organization_id,
t.name,
t.id_card,
t.sex,
t.birthday,
t.phone,
t.introduction,
t.subject_id,
t.position_type,
t.ntce_no,
t.status,
t.check_status,
t.remark,
o.name AS organization_name,
WM_CONCAT(si.name) AS subject_names, -- 使用WM_CONCAT函数将si.name字段合并为一个字符串
t.create_time
FROM
t_teacher_info t
JOIN
t_organization_info o ON o.id = t.organization_id
JOIN
sys_user su ON o.id = su.organization_id
JOIN
sys_dept sd ON sd.dept_id = su.dept_id
LEFT JOIN
t_teacher_subject ts ON ts.teacher_id = t.id
LEFT JOIN
t_subject_info si ON si.id = ts.subject_id
GROUP BY
t.id, -- 根据需要的字段进行分组,确保其他字段的唯一性
t.organization_id,
t.name,
t.id_card,
t.sex,
t.birthday,
t.phone,
t.introduction,
t.subject_id,
t.position_type,
t.ntce_no,
t.status,
t.check_status,
t.remark,
o.name,
t.create_time;
```
这样,查询结果中的subject_names列将包含了所有相关的si.name值,以逗号分隔。请确保根据你的需求适当调整其他字段的分组方式。
阅读全文