繁体   English   中英

MySQL查询:在这个月获得新客户

[英]MySQL Query: Get new customers in the month

我在表中有数百万条记录,其中包含以下列:

id, item_id, customer_id, date

我想查找特定月份的customer_id ,该月份会在该月的表格中首次插入。

什么是最好和最简单的查询。

谢谢

select customer_id , min(date) as min_date
from theTable
group by customer_id 
having min_date>=<the desired date>

尝试类似的东西:

SELECT
date_format(date,"%M") month,group_concat(customer_id ORDER BY customer_id) customer_ids
FROM
<table_name>
GROUP BY month;

这样的事情可能是:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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