This is my solution to the problem, without using join and with using just 1 cte: - with cte as ( SELECT * , FIRST_VALUE(order_date) OVER(partition by customer_id order by order_date) as first_ord FROM customer_orders ) select order_date ,SUM(case when order_date = first_ord then 1 else 0 end) as new_customer ,SUM(case when order_date != first_ord then 1 else 0 end) as repeated from cte group by order_date
great keep going
This is my solution to the problem, without using join and with using just 1 cte: -
with cte as (
SELECT
* ,
FIRST_VALUE(order_date) OVER(partition by customer_id order by order_date) as first_ord
FROM customer_orders
)
select
order_date
,SUM(case when order_date = first_ord then 1 else 0 end) as new_customer
,SUM(case when order_date != first_ord then 1 else 0 end) as repeated
from cte
group by order_date
Nice
My SQL or Ms SQL which Should I learn ?
Almost same learn sql server we have dedicated playlist..
@learnbydoingit ok bro