[英]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.