--drop table advert_sample_&period; select * from advert_sample_10
CREATE TABLE CL_ADVERT_SAMPLE_&period AS
SELECT  *
FROM    (
        SELECT  f.*, 
        case when f.last_date-f.first_date <= &period then 1 else 0 end sold_flag,
        count(distinct systemid) over (partition by brand) as brand_cnt
        FROM    flat_file_&period f
        where 1=1
        --and carosery not in ('OTHER')
        --and not (usedsince > to_date('20160101','yyyymmdd') and usedsince != to_date('29991231','yyyymmdd'))
        --and not (km > 1000000 and carosery not in ('OTHER'))
        ORDER BY
                dbms_random.value
        )
WHERE rownum <= 50000
;
select sold_flag, count(*) from advert_sample_&period group by sold_flag;

select * from advert_sample_&period where cubiccapacity > 20000 trunc(cubiccapacity/10)
hpower
power

--and brand not in ('','','')

select * from advert_sample_&period where km > 500000;
select * from advert_sample_&period where km_netto_delta < -500000;
select * from advert_sample_&period where km_netto_delta >  500000;

select * from advert_sample_&period where usage = -85;

select * from report where systemid = '670962fc9f077dc16859615ff2adaaa8';

select * from advert_sample_&period where brand = 'Zetor'