Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to flexible the results in oracle?

Author  Topic 

yingyang
Starting Member

1 Post

Posted - 2014-05-05 : 05:36:55
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. Please help me. I really need help.

Thank you.

Here's the sql script:

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;

robvolk
Most Valuable Yak

15732 Posts

Posted - 2014-05-05 : 07:03:35
I'm afraid your question isn't clear at all. Also, SQLTeam.com is a Microsoft SQL Server web site. There is an Oracle forum over at http://dbforums.com/
Go to Top of Page
   

- Advertisement -