Sobes.tech
Junior — Middle

Can you provide an example of complex SQL queries you have written in your practice?

sobes.tech AI

Answer from AI

An example of a complex SQL query from practice — a query with multiple JOINs, subqueries, and aggregate functions to obtain statistics on orders and customers:

SELECT c.customer_id, c.name, COUNT(o.order_id) AS total_orders, SUM(o.amount) AS total_amount
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
WHERE c.status = 'active'
GROUP BY c.customer_id, c.name
HAVING SUM(o.amount) > 1000
ORDER BY total_amount DESC;

This query selects active customers, counts their orders, sums the order amounts, filters for total amounts greater than 1000, and sorts by descending total amount. Such a query helps analyze key customers by sales volume.

Can you provide an example of complex SQL queries you… - sobes.tech