I want to count some data in a month after a specific date.
the table looks like this
date | user_id | tx_id |
---|---|---|
2022-07-08 | 123 | 1 |
2022-07-08 | 124 | 2 |
2022-07-10 | 123 | 3 |
I want to count every tx_id that user_id number 123 made in the a month from it’s first tx_id. like how many tx_id s does user 123 made from 2022-07-08 to 2022-08-08?
I couldn’t find any thing that can handle both finding if it’s first tx_id and counting the other tx_ids one month from that date.
3
Answers
use this query :
here is the optimized query without subquery:
How about grouping by user_id? Then count?
Count the number of transactions made by each user in the first month of their transaction.
eg
Here is a general solution: Use
NOT EXISTS
to only get the first month’s orders per user. Then count found rows per user.Here is the same with getting the first date per user and using
<=
: