Select Distinct STRING_AGG(Concat( fuel_type, ', ', litres ), '
') Over() as "fuel type | litres"
From ( Select fuel_type, Sum(litres) as litres
From tmp
Group By fuel_type
)
WITH FuelSums AS (
SELECT
fuel_type,
SUM(litres) AS total_litres
FROM
tmp2
GROUP BY
fuel_type
)
SELECT
STRING_AGG(CONCAT(fuel_type, ',', total_litres), '; ') AS fuel_data
FROM
FuelSums;