请详细的解释一下这个oracle的sql语句 select distinct comp.f_voucher_number as voucherNumber,task.f_dept_id as deptId,d.fdeptname as dept,d.FDEPTLEVEL as deptLevel, decode(d.FDEPTLEVEL,9,d6.fdeptname,8,d5.fdeptname,7,d4.fdeptname,6,d3.fdeptname,5,d2.fdeptname,4,d.fdeptname,'-') as divDepart, decode(d.FDEPTLEVEL,9,d6.fprincipal,8,d5.fprincipal,7,d4.fprincipal,6,d3.fprincipal,5,d2.fprincipal,4,d.fprincipal,'-') as divSender, decode(d.FDEPTLEVEL,9,d5.fdeptname,8,d4.fdeptname,7,d3.fdeptname,6,d2.fdeptname,5,d.fdeptname,'-') as bigDepart, decode(d.FDEPTLEVEL,9,d5.fprincipal,8,d4.fprincipal,7,d3.fprincipal,6,d2.fprincipal,5,d.fprincipal,'-') as bigSender, decode(d.FDEPTLEVEL,9,d4.fdeptname,8,d3.fdeptname,7,d2.fdeptname,6,d.fdeptname,'-') as smallDepart, decode(d.FDEPTLEVEL,9,d4.fprincipal,8,d3.fprincipal,7,d2.fprincipal,6,d.fprincipal,'-') as smallSender, decode(d.FDEPTLEVEL,9,d3.fdeptname,8,d2.fdeptname,7,d.fdeptname,'-') as saleDepart, decode(d.FDEPTLEVEL,9,d3.fprincipal,8,d2.fprincipal,7,d.fprincipal,'-') as saleSender from dpcrm.T_COMP_COMPLAINT comp left join dpcrm.T_COMP_TASKDEPT task on comp.f_id = task.f_comp_id left join dpcrm.t_org_department d on d.fid = task.f_dept_id left join dpcrm.t_org_department d2 on d2.fid = d.fparentid left join dpcrm.t_org_department d3 on d3.fid = d2.fparentid left join dpcrm.t_org_department d4 on d4.fid = d3.fparentid left join dpcrm.t_org_department d5 on d5.fid = d4.fparentid left join dpcrm.t_org_department d6 on d6.fid = d5.fparentid where comp.f_time_report >= sysdate - 1 and task.f_directory_two = '催派送'
时间: 2023-06-26 17:07:55 浏览: 162
ORACLE__SQL语句教学 ORACLE
这个 SQL 语句是用来查询 `dpcrm.T_COMP_COMPLAINT` 表中提交时间在最近一天内且任务类型为“催派送”的投诉单信息。具体查询的字段包括:
- `comp.f_voucher_number`:投诉单号
- `task.f_dept_id`:任务所属部门的 ID
- `d.fdeptname`:任务所属部门的名称
- `d.FDEPTLEVEL`:任务所属部门的层级
- `decode(d.FDEPTLEVEL,9,d6.fdeptname,8,d5.fdeptname,7,d4.fdeptname,6,d3.fdeptname,5,d2.fdeptname,4,d.fdeptname,'-')`:根据任务所属部门的层级,选择对应级别的部门名称。如果没有对应级别的部门,返回 `-`
- `decode(d.FDEPTLEVEL,9,d6.fprincipal,8,d5.fprincipal,7,d4.fprincipal,6,d3.fprincipal,5,d2.fprincipal,4,d.fprincipal,'-')`:根据任务所属部门的层级,选择对应级别的部门负责人。如果没有对应级别的部门,返回 `-`
其中,`decode` 函数是用来实现根据不同条件选择不同返回值的功能。每个 `decode` 函数中都有一组类似的条件和返回值,例如 `decode(d.FDEPTLEVEL,9,d6.fdeptname,8,d5.fdeptname,7,d4.fdeptname,6,d3.fdeptname,5,d2.fdeptname,4,d.fdeptname,'-')`,它的意思是:
- 如果任务所属部门的层级为 9,返回 `d6.fdeptname`
- 如果任务所属部门的层级为 8,返回 `d5.fdeptname`
- 如果任务所属部门的层级为 7,返回 `d4.fdeptname`
- 如果任务所属部门的层级为 6,返回 `d3.fdeptname`
- 如果任务所属部门的层级为 5,返回 `d2.fdeptname`
- 如果任务所属部门的层级为 4,返回 `d.fdeptname`
- 如果任务所属部门的层级不在上述范围内,返回 `-`
阅读全文