sql - Getting a count while accounting for an attribute -


I have two tables, one for account information and one for customer information One account has many customers associated with it May be. All I want to do is catch all the active customers in the given month. However, I also want to create an account for those customers who have been active and bought in the previous months.

account id IND_ID LAST_PURCHASE 1 101 2013-01-15 2 102 2013-03-20 2 103 2013-02-05 3 104 2013-07-25 4 105 2012-01-11 Customers ID Status 101A 102A 103A 104E 105A

Select only active customers, this is not a problem because I can filter just on that column. However, how can I choose to count 'active' customers for the people purchased in the last 2 months?

You can filter it by looking at the maximum purchase date and:

  Choose from customer C to add the c.id account to c.id = a.ind_id where c. Status = 'A' is group c.id, maximum (last_punch) & gt; = Date_add (month, -2, meet ());  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -