Skip to content
Advertisement

How to find records within a certain timeframe based on another field

How do I find all records 7 days before a field in an SQL database?

I need to find all transaction dates that were placed 7 days before the pickup date of the same record.

I am currently using SequelPro so that my have an effect on available syntaxes.

This is currently my table that I am pulling the records from.

photo of table and its content

This is the exact question I am being asked;

Write a query to display all details of transactions that were made at least one week before the pickup date.

Advertisement

Answer

Isn’t it straightforward?

SELECT * FROM TransactionTable
WHERE DATEDIFF(pickupdate, transactiondate) >= 7;
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement