Writing a query is an art! Simplicity, focus, and practice is all it takes. Understand the logical processing of a query and discover the art of writing simple and efficient queries. It is a journey that starts with FROM and ends with ORDER BY!
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Zen and the Art of Writing SQL Query
1.
2.
3. SELECT C.customer_name,
SUM(O.order_amount) AS total
FROM Customers AS C
JOIN Orders AS O
ON C.customer_nbr = O.customer_nbr
WHERE C.customer_name LIKE 'J%'
AND O.order_date >= '20090101'
AND O.order_date < '20100101'
GROUP BY C.customer_name
HAVING SUM(O.order_amount) > 10
ORDER BY total DESC;
4. SELECT C.customer_name,
SUM(O.order_amount) AS total
FROM Customers AS C
JOIN Orders AS O
ON C.customer_nbr = O.customer_nbr
WHERE C.customer_name LIKE 'J%'
AND O.order_date >= '20090101'
AND O.order_date < '20100101'
GROUP BY C.customer_name
HAVING SUM(O.order_amount) > 10
ORDER BY total DESC;
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17. SELECT C.customer_name,
SUM(O.order_amount) AS total
FROM Customers AS C
JOIN Orders AS O
ON C.customer_nbr = O.customer_nbr
WHERE C.customer_name LIKE 'J%'
AND O.order_date >= '20090101'
AND O.order_date < '20100101'
GROUP BY C.customer_name
HAVING SUM(O.order_amount) > 10
ORDER BY total DESC;