Link to home
Start Free TrialLog in
Avatar of Anthony Matovu
Anthony MatovuFlag for Uganda

asked on

get the maximum value on a condition

Dear All

I want to write a sql statement giving me the most recent date when a customer paid for different products by product

Result should be like this

Customer ='James", last_date_paid_for_product1='20160101", last_date_paid_for_product2='20160201", last_date_paid_for_product2
3='20160201",

Data is in this format
Customer            Date_of_pay         Product1          Product2           Product3
A                           20161010                200                                                300
A                           20161011                200                                                
A                           20161012                200                                                
A                           20161013                                           400                     300
A                           20161014                                                                      300

Result of the sql should be
Customer ='A", last_date_paid_for_product1='20161012", last_date_paid_for_product2='20161013", last_date_paid_for_product2
3='20161014",


Thank you

Anthony
ASKER CERTIFIED SOLUTION
Avatar of chaau
chaau
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access

did you make a mistake? did you mean to write this:
Customer ='A', last_date_paid_for_product1='20161012', last_date_paid_for_product2='20161013', last_date_paid_for_product3='20161014'

What is the data type for Date_of_pay ?
You should rephrase this completely. You state two different resultsets, and have tagged the question wildly:

MS SQL Server MS Access .NET Programming

so no one knows what your are doing.

/gustav