CREATE TABLE SalesByQuarter3
(year INT,
quarter CHAR(2),
amount MONEY,
ticket INT IDENTITY PRIMARY KEY
)


SELECT SQ1.year, Q1, Q2, Q3, Q4
FROM (
SELECT year, SUM(amount) AS Q1
From SalesByQuarter GROUP BY year, quarter
HAVING quarter='Q1') AS SQ1
JOIN (
SELECT year, SUM(amount)  AS Q2
From SalesByQuarter GROUP BY year, quarter
HAVING quarter='Q2') AS SQ2
ON SQ1.year = SQ2.year
JOIN (
SELECT year, SUM(amount) AS Q3
From SalesByQuarter GROUP BY year, quarter
HAVING quarter='Q3') AS SQ3
ON SQ2.year = SQ3.year
JOIN (
SELECT year, SUM(amount) AS Q4
From SalesByQuarter GROUP BY year, quarter
HAVING quarter='Q4'
) AS SQ4
ON SQ3.year = SQ4.year
ORDER BY SQ1.year DESC