with great_design_tab as (
select 700 as id, '1,11,32,531' as ass_pain from dual union all
select 701 as id, '2, 44, 321' as ass_pain from dual
)
,usrs as (
select 1 as id, 'вася' as username from dual union all
select 11 as id, 'петя' as username from dual union all
select 32 as id, 'костя' as username from dual union all
select 531 as id, 'дима' as username from dual union all
select 2 as id, 'жора' as username from dual union all
select 44 as id, 'изя' as username from dual union all
select 321 as id, 'семен' as username from dual
)
select u.id, u.username, t.id
from usrs u
,great_design_tab t
,lateral (
select level x from dual
connect by regexp_substr(ass_pain, '[^,]+', 1, level) is not null
)
where u.id = trim(regexp_substr(ass_pain,'[^,]+', 1, x));
ID USERNAME ID
---------- -------- ----------
1 вася 700
11 петя 700
32 костя 700
531 дима 700
2 жора 701
44 изя 701
321 семен 701
WITH dt_range AS (
SELECT TRUNC (&dt_start + ROWNUM - 1) dt
FROM DUAL CONNECT BY ROWNUM <= &dt_end - &dt_start + 1
)
,bal AS (
SELECT 101 id_, to_date('20171130', 'yyyymmdd') date_, 50 sum_ FROM DUAL UNION ALL
SELECT 101, to_date('20180102', 'yyyymmdd'), 300 FROM DUAL UNION ALL
SELECT 101, to_date('20180105', 'yyyymmdd'), 500 FROM DUAL UNION ALL
SELECT 101, to_date('20180107', 'yyyymmdd'), 700 FROM DUAL
)
SELECT id_ --MAX(id_) OVER (PARTITION BY grp) id_
,dt
,MAX(sum_) OVER (PARTITION BY grp) sum_
FROM (
SELECT t1.*
,SUM(start_of_group) OVER(ORDER BY t1.dt) grp
FROM (
SELECT bal.id_
,dt_range.dt
,bal.sum_
,CASE WHEN bal.sum_ IS NOT NULL THEN 1 END start_of_group
FROM dt_range
LEFT JOIN bal ON dt_range.dt = bal.date_
) t1
)
ORDER BY dt
SELECT *
FROM logRF
where fio like IFNULL('%".$_POST['fio']."%', fio)
AND b_date = IFNULL('%".$_POST['b_date']."%', b_date)
AND city = IFNULL('%".$_POST['city ']."%', city)
HAVING COUNT(DISTINCT type) = 1
with t as(
select 1 as chld_id, null as prnt_id, '1_name' as nm from dual union all
select 3 as chld_id, 1 as prnt_id, '3_name' as nm from dual union all
select 4 as chld_id, 1 as prnt_id, '4_name' as nm from dual union all
select 6 as chld_id, 9 as prnt_id, '6_name' as nm from dual union all
select 9 as chld_id, 3 as prnt_id, '9_name' as nm from dual union all
select 12 as chld_id, 9 as prnt_id, '12_name' as nm from dual union all
select 14 as chld_id, 9 as prnt_id, '14_name' as nm from dual union all
select 15 as chld_id, 3 as prnt_id, '15_name' as nm from dual union all
select 18 as chld_id, 9 as prnt_id, '18_name' as nm from dual
)
select
prnt_id, chld_id, nm
from t
where prnt_id is not null
order by 1,2
select
prnt_id
,chld_id
,level
,lpad(' ', 4*level)||nm as hierarchy_
from t
start with prnt_id is null
connect by prior chld_id = prnt_id
order by prnt_id nulls first, chld_id;