如何在oracle中灵活处理结果?

时间:2014-05-05 06:24:54

标签: sql oracle plsql oracle-sqldeveloper plsqldeveloper

如何让我的脚本变得灵活?我的意思是,如果在表中添加了新人,则不需要在sql脚本中进行修改。请帮我。我真的需要帮助。

谢谢。

这是sql脚本:

select 'Data'
||','||to_char(d.dtime_day,'MM/dd/yyyy')
||','||nvl(d.total,0)
||','||nvl(r.total,0)
||','||nvl(rj.total,0)
||','||nvl(a.total,0)
from table1 d
left join(
      select trunc(t.create_time, 'DD') as ddate
            ,u.name as person1
            ,count(t.responsible_user_id) as total
      from table2 t
      left join table3 u
      on t.responsible_user_id=u.id
      where u.id in (3,35)
      and u.title like '%name'
      group by trunc(t.create_time, 'DD')
              ,u.name
 ) d on d.dtime_day = d.ddate
 left join(
      select trunc(t.create_time, 'DD') as ddate
            ,u.name as person2
            ,count(t.responsible_user_id) as total
      from table2 t
      left join table3 u
      on t.responsible_user_id=u.id
      where u.id in (4,39)
      and u.title like '%name'
      group by trunc(t.create_time, 'DD')
              ,u.name
  ) r on d.dtime_day = r.ddate
  left join(
      select trunc(t.create_time, 'DD') as ddate
            ,u.name as person3
            ,count(t.responsible_user_id) as total
      from table2 t
      left join table3 u
      on t.responsible_user_id=u.id
      where u.id in (8,59)
      and u.title like '%name'
      group by trunc(t.create_time, 'DD')
              ,u.name
 ) rj on d.dtime_day = rj.ddate
 left join(
      select trunc(t.create_time, 'DD') as ddate
            ,u.name as person4
            ,count(t.responsible_user_id) as total
      from table2 t
      left join table3 u
      on t.responsible_user_id=u.id
      where u.id in (25)
      and u.title like '%name'
      group by trunc(t.create_time, 'DD')
              ,u.name
  ) a on d.dtime_day = a.ddate
  where d.dtime_day between trunc(sysdate,'DD')-12*7 and trunc(sysdate) -1
 and trunc(d.dtime_day, 'DD')= d.dtime_day
 order by d.dtime_day;

1 个答案:

答案 0 :(得分:-1)

我没有尝试这个,但我认为你可以从SQL脚本创建一个视图,之后你可以创建一个触发器,它在插入键之前触发并替换视图。
这只是一个想法。