lundi 3 avril 2017

Applying if logic in SQL query?

my Database table is in the format as shown below :

Current Year = 2017

ID     Bought    Year
1       A        2016
1       A        2015
2       A        2013
2       B        2015 
2       B        2014
3       A        2014
4       A        2014 
4       A        2015  
4       A        2016 

List the customers who have been buying Product'A' last two years ( Bought in both T-1 and T-2 year )

Ans - ID : 1 and 4

How do I formulate a query in R , using

lasttwoyearcustlist=DBgetQuery(conn, "Query") 

Aucun commentaire:

Enregistrer un commentaire