Find top 10 customers with the highest lifetime value (total…

Find top 10 customers with the highest lifetime value (total amount spent on orders). List customer’s fullname, total amount spent, the first foods they have ordered i.e. the food_names in their first order, and the last food they have ordered so far (food_names in their last order).

What is the following query returning? WITH a AS (    SELECT…

What is the following query returning? WITH a AS (    SELECT food_name, SUM(oi.quantity) as sum_quantity    FROM Orders o        LEFT JOIN Order_Items oi ON oi.order_id = o.order_id        LEFT JOIN Food f ON f.product_id = oi.product_id    GROUP BY 1    QUALIFY Count( DISTINCT o.order_id) OVER (PARTITION BY customer_id)>1)SELECT food_nameFROM aQUALIFY DENSE_RANK() OVER (ORDER BY sum_quantity DESC) < 4