Let's say I require a distinct count for each year with specific criteria as per where statement and x below being various years 2000 to 2016:
dbGetQuery(conn, "SELECT COUNT(DISTINCT ID)
FROM table x
WHERE cust_STATUS_DESC like '%matured%'
and YEAR(END_DATE) in ("x") ") )
How do I do this using a for loop or apply function?