Home > database > Great god genuflect is begged for advice, how to use the SQL statistics on the number of effective c
Great god genuflect is begged for advice, how to use the SQL statistics on the number of effective c
Time:11-24
Effective customer is defined as: nearly a year into the shop customers, statistics a fixed time I go back to the statistics, but at once if you want to put every month this year are displayed, just don't understand how to write the SQL?
For example:
Effective customer is in March 2020, in March 2019 to May 2020 in shop customer Effective customer is in April 2020, in April 2019 to May 2020 in shop customer Effective customer is in May 2020, in May 2019 to May 2020 in shop customer .
Now at the same time show
Effective number of clients in In January, In February, In march, In April, In may,
Thank you for the great god give directions!
CodePudding user response:
You have customers into the store in the table of consumption time First time for years, according to the monthly group had sum amount
SELECT YearMonth, COUNT (client) AS 'customers' FROM Table GROUP BY YearMonth
If you want to repeat it
SELECT YearMonth, COUNT (Distinct customer) AS 'customers' FROM Table GROUP BY YearMonth