Reputation: 21
I have a table [Usage] with uniqueness on [Usage.Address & Usage.TransactionDate]. I am attempting to create a query that lists Usage.Address, Usage.TransactionDate, and a field that counts the records with the same Address where TransactionDate is plus or minus 60 days of the TransactionDate. How do I do this?
Upvotes: 0
Views: 83
Reputation: 1269493
You can use a correlated subquery:
select u.*,
(select count(*)
from usage as u2
where u2.address = u.address and
u2.transactionDate >= dateadd("d", -60, u.transactionDate) and
u2.transactionDate <= dateadd("d", 60, u.transactionDate)
) as new_field
from usage as u;
Upvotes: 1