简体   繁体   中英

MySQL Query: Get new customers in the month

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;

Something like this may be:

select distinct(id) from customer
where month(date)='Your_month'
order by date

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM