Zen and the Art of Writing SQL Query

1,608 views
1,356 views

Published on

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!

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,608
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
25
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Zen and the Art of Writing SQL Query

  1. 1. 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;
  2. 2. 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;
  3. 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;

×