query optimization - MySQL compare data from date ranges prior to the current row and count() them -


this in reference still-open question here - want try approach differently.

i have mysql table 2 pieces of information: order_date , email_address. exhaustive , non-distinct, meaning there duplicates if happened make more 1 purchase per-day.

i need following report in few queries possible, one:

yyyy-mm | number_emails_this_month | numer_emails_repeated_prior 

where sample output query result this:

yyyy-mm | number_emails_this_month | numer_emails_repeated_prior 2010-02     23423               1231 2010-03     4422                2234 2010-04     1424                650 

any appreciated!

i not sure understand number_emails_repeated_prior. if post short example of data , corresponding example of wanted results helpful.

taking guess aiming for, number of emails specific user per month need is:

select date_format(order_date, '%y-%m') `yyyy-mm`,         count(email_address) `number_emails_this_month ` table_name email_address = 'some@address' group 1 order 1 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -