This video is about finding new and repeat customers .using SQL. In this video we will learn following concepts:
how to approach complex query step by step
how to use CASE WHEN with SUM
how to use common table expression (CTE)
Here is the script :
create table customer_orders (
order_id integer,
customer_id integer,
order_date date,
order_amount integer
);
select * from customer_orders
insert into customer_orders values(1,100,cast('2022-01-01' as date),2000),(2,200,cast('2022-01-01' as date),2500),(3,300,cast('2022-01-01' as date),2100)
,(4,100,cast('2022-01-02' as date),2000),(5,400,cast('2022-01-02' as date),2200),(6,500,cast('2022-01-02' as date),2700)
,(7,100,cast('2022-01-03' as date),3000),(8,400,cast('2022-01-03' as date),1000),(9,600,cast('2022-01-03' as date),3000)
;
Негізгі бет Complex SQL 2 | find new and repeat customers | SQL Interview Questions
Пікірлер: 587