
create or replace table users as from read_csv(getvariable('bucket') || '/bronze/users.csv');

create or replace table orders as from read_csv(getvariable('bucket') || '/bronze/orders.csv');

select (select count(*) from users) as users, (select count(*) from orders) as orders;

select min(date) as first_order,   max(date) as last_order from orders;


select count(*) as orphan_orders from orders o 
anti join users u on o.user_uuid = u.uuid;

select count(*) as inactive_users from users u 
anti join orders o on o.user_uuid = u.uuid;

select uuid, count(*) as occurrences from orders group by uuid having count(*) > 1;
