\textbf{Feature:} This query is used to retrieve the demographics of customer activity. \\
\textbf{Location:} In function \texttt{admin\_stats(page)} in \texttt{front-end/\_\_init\_\_.py}

\textbf{Usage:}
The OLAP data contains the number of customers that are registered on EBMS grouped by demographics.
Empty values in the field \texttt{state} indicate that the data is an aggregate of country-wise data.
The data record where country is empty gives the global aggregated data.
The average spending per order along with total spending is also shown.

\begin{lstlisting}
SELECT
    country, state,
    COUNT(DISTINCT customer.customerID) AS customer_count,
    AVG(product.price * order_product.quantity) AS avg_spent,
    SUM(product.price * order_product.quantity) AS total_spent
FROM customer
JOIN orders ON customer.customerID = orders.customerID
JOIN order_product ON orders.orderID = order_product.orderID
JOIN product ON order_product.productID = product.productID
JOIN address ON customer.addressID = address.addressID
GROUP BY country, state WITH ROLLUP
ORDER BY country ASC, total_spent DESC;
\end{lstlisting}
