USE hahn;


insert into `//home/taxi-delivery/analytics/dev/product/uber/uber_orders_deliveries_dynamics_all_test_zones` with truncate
SELECT
    tariff_zone
    ,   order_created_date
    ,   count(distinct order_id) as order_cnt
    ,   count(distinct 
                    case when success_order_flg
                        then order_id
                        else NULL
                        end
        ) as trips_cnt
    ,   count(distinct 
                    case when success_order_flg
                        then order_id
                        else NULL
                        end
        ) / count(distinct order_id) as CR
FROM 
    range('//home/taxi-dwh/summary/dm_order', '2021-09')
WHERE
    not fake_order_flg
    and not mqc_order_flg
    and country = 'Россия'
    and order_tariff in ['ubernight']
    and order_source in ['yauber']
    and corp_client_id is null
    and utc_order_dt >= '2021-09-24'
group by tariff_zone
    ,   cast(utc_order_dt as Date) as order_created_date 
order by tariff_zone
    ,   order_created_date;
