I have millions of records in a table with following columns:
id, item_id, customer_id, date
I want to find customer_id
for a specific month which are inserted first time in the table in that month.
What is best and simple query for this.
Thanks
select customer_id , min(date) as min_date
from theTable
group by customer_id
having min_date>=<the desired date>
try something like:
SELECT
date_format(date,"%M") month,group_concat(customer_id ORDER BY customer_id) customer_ids
FROM
<table_name>
GROUP BY month;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With