枝我想如下從中提取3個表及其行的數據顯示30天的查詢:
**RentalAgreement – CustID,AgreementID(PK) and AgreementDate **Movie Rented – AgreementID(PK), RentalAmount and PercentReductionApplied,MovieID(FK) **Movie – MovieID(PK), Name, Released
獲得可以根據表中的數據,而不是當前的日期
,我需要顯示從數據最近30天根據表而不是當前數據。 我該如何去實現這一目標? 我的嘗試:
SELECT TRIM(CustID),AgreementDate , RentalAmount
,PercentReductionApplied , MovieID , Name , Released
FROM RentalAgreement, MovieRented, Movie
WHERE RentalAgreement.AgreementID = MovieRented.AgreementID
AND Movie.MovieID = MovieRented.MovieID
AND AgreementDate BETWEEN MAX(AgreementDate) AND MAX(AgreementDate)-30;