简体   繁体   English

如何在oracle中灵活显示结果?

[英]How to flexible the results in oracle?

How to make my script to be flexible? 如何使我的脚本更灵活? I mean, if there's a new person added in the table, it would not need to do a modification in the sql script. 我的意思是,如果表中添加了一个新人员,则无需在sql脚本中进行修改。 Please help me. 请帮我。 I really need help. 我真的需要帮助

Thank you. 谢谢。

Here's the sql script: 这是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;

I didn't try this but I think you can create a view from the SQL script, after that you can create a trigger which triggers before insert key and replaces the view. 我没有尝试过,但是我认为您可以从SQL脚本创建视图,之后您可以创建触发器,该触发器在插入键并替换视图之前触发。
it's just an idea. 这只是一个想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM