How to count new element occurrences in SQL?

Let's say I have a table of orders with fields: user_id, created_at.

I want to create a query that shows how many NEW user_id appeared per day.

This shows how many orders were in a day:

SELECT count(1), TO_CHAR(created_at, 'YYYY-MM-DD') as day FROM orders GROUP BY day ORDER BY day DESC 
+4
source share
1 answer
 SELECT count(1), TO_CHAR(FirstOrder, 'YYYY-MM-DD') AS day FROM (SELECT MIN(created_at) AS FirstOrder, user_id FROM orders GROUP BY user_id) first_orders GROUP BY TO_CHAR(FirstOrder, 'YYYY-MM-DD') ORDER BY day DESC 
+3
source

Source: https://habr.com/ru/post/1480350/


All Articles