0

I want to make a sql for statistic over customers. I would like to print all customers from may, april, juni, july and so on. Example:

  • In jan i have 20 new customers
  • In feb i have 5 new customers
  • In Mar i have 10 new customers
  • ..... and so on

My database look like

 `id` int(11) NOT NULL AUTO_INCREMENT,
 `displayName` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `firstname` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `lastname` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `phoneNo` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `website` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `industry_Id` int(11) NOT NULL,
 `date` date NOT NULL,
Victor
  • 57
  • 4
  • What do you mean by "new customer"? What does your table have to do with "customers"? – Gordon Linoff Dec 18 '19 at 23:42
  • Im justing make a small CRM. And would like to see how many customers im making each month. For statistics. So I can in 2 years look back at my business and see how it goes. – Victor Dec 18 '19 at 23:43
  • Does this answer your question? [MySQL Query GROUP BY day / month / year](https://stackoverflow.com/questions/508791/mysql-query-group-by-day-month-year) – A. S. K. Dec 18 '19 at 23:56
  • "My database look like" -- Unless you somehow managed to have free floating columns, you rather mean "table" not "database".... – sticky bit Dec 19 '19 at 00:42
  • @stickybit Yeah ofcorse :D haha – Victor Dec 19 '19 at 11:55

1 Answers1

2

Do you just want aggregation?

select date_format(c.date, '%Y-%m') mon, count(*) cnt
from customers c
group by date_format(c.date, '%Y-%m')
GMB
  • 216,147
  • 25
  • 84
  • 135