I not sure how to do this.Could anyone can help me...?
question:
Display all buyer (code, name) who has average purchase each year for more than 100000 for past 10 years
here is my query:
SELECT b.CODE, b.NAME from
(
SELECT BUYER, AVG(TOTAL) AS total
FROM SMF
WHERE TOTAL > 100000
and PERIOD1 > DATEADD(YEAR, -10, GETDATE())
group by BUYER
) a
inner join ACCODE b on b.CODE = a.BUYER
thank you for helping....