mysql add tag
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
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]( function is used to check whether their first transaction was on Monday.

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.