MySQL查询:当月新增客户

MySQL查询:当月新增客户,mysql,sql,Mysql,Sql,我在一个包含以下列的表中有数百万条记录: id, item_id, customer_id, date 我想查找特定月份的customer\u id,该月份第一次插入表中 对于这个问题,最简单的查询是什么 谢谢像这样的事情可能是: select distinct(id) from customer where month(date)='Your_month' order by date 尝试以下方法: SELECT date_format(date,"%M") month,group_con

我在一个包含以下列的表中有数百万条记录:

id, item_id, customer_id, date
我想查找特定月份的
customer\u id
,该月份第一次插入表中

对于这个问题,最简单的查询是什么


谢谢

像这样的事情可能是:

select distinct(id) from customer
where month(date)='Your_month'
order by date
尝试以下方法:

SELECT
date_format(date,"%M") month,group_concat(customer_id ORDER BY customer_id) customer_ids
FROM
<table_name>
GROUP BY month;
选择
日期格式(日期,“%M”)月,集团公司(按客户id排序的客户id订单)客户id
从…起
按月分组;
选择客户id、最小(日期)作为最小日期
从表格
按客户id分组
有最小日期>=

您所说的首次插入是什么意思???@aviseks:表示表中的第一条客户id记录。
select customer_id , min(date) as min_date
from theTable
group by customer_id 
having min_date>=<the desired date>