I have this query that gives me the name of the item, the average price and the count for a specific year as below.
name Avg_price_2019 count
---------------------------------
X 23.9 234
Y 21.8 59
SQL:
SELECT
AVG(Amount) Avg_price_2019, name
FROM
(SELECT
name, SUM(price_amount) Amount, COUNT(*)
FROM
myTable
WHERE
(To_date("Activity Date", 'mm-dd-yyyy') >= TO_DATE('09/01/2019', 'mm/dd/yyyy'))
AND (To_date("Activity Date", 'mm-dd-yyyy') <= TO_DATE('09/17/2019','mm/dd/yyyy'))
GROUP BY
name)
GROUP BY
name;
I want it to return more years as below
name | Avg price 2018 | count | Avg price 2019 | count
For the results of 2018, I need the same query just changing the year.
How can I combine these two selects in the same query to produce the above result?