Anonymous 2043
query to get the count of users whose first transaction was on a Monday for each merchant. Your answer should have two columns - merchant_name, count of users who transacted for the first time and it was a Monday
transaction table:
transaction_id, user_id, merchant_name, transaction_date, amount
Top Answer
FoggyFinder
It would be easier to write a query if you provide test data.
Anyway, I think something like that could work
```
select merchant_name, count(*)
from (
select user_id, merchant_name, MIN(transaction_date) as date from transaction
group by user_id, merchant_name
having DAYOFWEEK(date) = 2
) as t
group by merchant_name;
```
Here we use a subquery to filter users and [DAYOFWEEK](https://www.w3resource.com/mysql/date-and-time-functions/mysql-dayofweek-function.php) function is used to check whether their first transaction was on Monday.