Hey guys,
I'm a complete n00b when it comes to queries and SQL, so please forgive my ignorance. I have trawled Google for anything that might help, but alas.. I'm making no progress!
I'm amending an existing query on a customers event management database, which basically pulls a list of all the establishments from tblEstablishment, then counts InvoiceID in tblEventDelegate to calculate the number of times a particular establishment has used services from the company.
What I'd like to do is also only show establishments that have used services in the last 2 years from when the query is run. The field 'TimeStamp' (in format: DD/MM/YYY HH:MM:SS) in TblEventDelegate could be used to perform this calculation, or there are also fields for invoice date etc.
Here is the current query sql:
Code:
SELECT TOP 5000 tblEstablishment.EstablishmentName, tblEstablishment.Address1, tblEstablishment.Address2, tblEstablishment.Address3, tblEstablishment.PostTown, tblEstablishment.County, tblEstablishment.PostalCode, Count(tblEventDelegate.InvoiceID) AS CountOfInvoiceID
FROM tblEstablishment RIGHT JOIN tblEventDelegate ON tblEstablishment.EstablishmentID = tblEventDelegate.EstablishmentID
GROUP BY tblEstablishment.EstablishmentName, tblEstablishment.Address1, tblEstablishment.Address2, tblEstablishment.Address3, tblEstablishment.PostTown, tblEstablishment.County, tblEstablishment.PostalCode
ORDER BY Count(tblEventDelegate.InvoiceID) DESC;
What would be the best way of me filtering the resulting data? To be honest even if I was able to pull the 'TimeStamp' field into the data that would be useful.
Any help appreciated