I have this block of data
https://www.db-fiddle.com/f/vXApR1qr7nQhcg5t2Tuxkx/1
So I would like to obtain the total sales,total active customers ,average spend per customer and avg spend per transaction in ONE SQL query.
Is this possible to do?
Here is the query that I have done but the subquery is not working for me. Please help.
select year(transdate) as year,truncate(sum(price * quantity),2) AS totalsales,COUNT(DISTINCT(b.custid)) as activecustomers,
SELECT truncate(AVG(total),2) AS AVERAGE
FROM (SELECT custid, sum(price*quantity) AS total
FROM transaction GROUP BY custid) A
;
from transaction
where transdate >= '2018-01-01' and transdate <= '2019-12-31'
group by YEAR(transdate)
