Приветствую!
Говорят, что это простое задание, но я ничерта не могу найти ошибок, а что могу - в том не уверен. Реальной базы данных нет, есть только вот этот текст запроса:
select name_r 'Имя', rtpl_id rtpl,
count(distinct case s<153 then subs_id else null end) x153,
count(distinct case when 153<=s and s<306 then subs_id else null end) x306,
count(distinct case when 305<=s and s<459 then subs_id else null end) x459,
count(distinct case when 459<=s and s<612 then subs_id else null end) x612,
count(distinct case when 612<=s and s<765 then subs_id else null end) x765,
count(distinct case when 765<=s and s<918 then subs_id else null end) x918,
count(distinct case when 918<=s and s<1071 then subs_id else null end) x1071,
count(distinct case when 1071<=s and s<1224 then subs_id else null end) x1224,
count(distinct case when 1224<=s and s<1377 then subs_id else null end) x1377,
count(distinct case when 1377<=s and s<1530 then subs_id else null end) x1530,
count(distinct case when 1530<=s and s<2294 then subs_id else null end) x2294,
count(distinct case when 2294<=s and s<3059 then subs_id else null end) x3059,
count(distinct case when 3059<=s then subs_id else null end) y3059
from (
select s.subs_id, case when nvl(c.subs_count,0)<>0 then amount_r/c.subs_count else 0 end "s", x.name_r, x.rtpl_id
from r_20070730 r, agg.client_d c , agg.subs_d s,
(select * from bis.rate_plans x where x.end_date='31.12.2999') x
where c.d='01/07/2007'
and s.d=to_date('01.07.2007','dd.mm.yyyy')
and c.client_id=r.clnt_clnt_id
and s.client_id=c.client_id
-- and s.status_bu in (4,6)
and s.sbst_id = 2 and s.status_bu = 4
and s.rtpl_id=x.rtpl_id
and x.rtpl_id not in [0,169]
)
group by name_r, rtpl_id rtpl
Спасибо за уделённое время!