Junior — Middle
Have you ever written complex SQL queries for working with databases?
sobes.tech AI
Answer from AI
Yes, I have had to write complex SQL queries, for example, to retrieve data with multiple JOINs, subqueries, and aggregate functions. For instance, a query to get a list of clients with the total amount of their orders over the last year and filtering by certain conditions:
SELECT c.customer_id, c.name, SUM(o.amount) AS total_orders
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
WHERE o.order_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR)
GROUP BY c.customer_id, c.name
HAVING total_orders > 1000
ORDER BY total_orders DESC;
Such a query helps to obtain aggregated information and use filters and sorting for data analysis.