{"id":83,"date":"2025-11-04T18:24:27","date_gmt":"2025-11-04T18:24:27","guid":{"rendered":"http:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/?page_id=83"},"modified":"2025-11-07T14:04:08","modified_gmt":"2025-11-07T14:04:08","slug":"sql-madness-getting-ready-for-big-challenges","status":"publish","type":"page","link":"https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/sql-madness-getting-ready-for-big-challenges\/","title":{"rendered":"SQL Madness getting ready for big challenges"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Aurora SQL Warm-up \u2014 Student Worksheet<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Individual work<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-medium-font-size\">Context<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This worksheet accompanies the SQL warm-up dataset (classic retail schema) and is intended to support the expression of OLAP queries in a separate exercise.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><strong>Objective<\/strong>:<\/em>&nbsp;Practise basic SQL syntax, filtering, joins, grouping, and subqueries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>SQL Memento<\/em>:&nbsp;<a href=\"http:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/cheat-sheets\/\" data-type=\"page\" data-id=\"76\">cheat sheets<\/a><br><em>Dataset<\/em>: customers, employees, suppliers, categories, products, orders, order_items<a href=\"applewebdata:\/\/69F77F17-4E3A-4DC7-B5E7-D1CF2BBBAE82#_ftn1\"><sup>[1]<\/sup><\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"601\" src=\"http:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-content\/uploads\/sites\/64\/2025\/11\/erd-1024x601.jpg\" alt=\"\" class=\"wp-image-86\" srcset=\"https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-content\/uploads\/sites\/64\/2025\/11\/erd-1024x601.jpg 1024w, https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-content\/uploads\/sites\/64\/2025\/11\/erd-300x176.jpg 300w, https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-content\/uploads\/sites\/64\/2025\/11\/erd-768x451.jpg 768w, https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-content\/uploads\/sites\/64\/2025\/11\/erd-1536x902.jpg 1536w, https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-content\/uploads\/sites\/64\/2025\/11\/erd-2048x1203.jpg 2048w, https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-content\/uploads\/sites\/64\/2025\/11\/erd-500x294.jpg 500w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-medium-font-size\">ToDo \u2013 ToTest<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><em>Execution Environment &amp; Setup<\/em><\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">There are two alternatives to have access to externalised PostgreSQL SQL environments with no installation burden required:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Aurora PostgreSQL or Aurora MySQL (version \u22658)&nbsp;<a href=\"https:\/\/sqliteonline.com\/\">https:\/\/sqliteonline.com<\/a>\n<ul class=\"wp-block-list\">\n<li>Create an account (attention!&nbsp;<strong>limited number<\/strong>&nbsp;of queries allowed! so avoid testing too much).<\/li>\n\n\n\n<li>Choose the PostgreSQL option.\n<ul class=\"wp-block-list\">\n<li>Use the following script to setup your environment:<a href=\"https:\/\/drive.google.com\/file\/d\/1xt2DnQJFUMvURbz-cSUfgBaa954Mopqv\/view?usp=sharing\">https:\/\/drive.google.com\/file\/d\/1xt2DnQJFUMvURbz-cSUfgBaa954Mopqv\/view?usp=sharing<\/a><br><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>PostgreSQL externalized cloud (<strong>recommended<\/strong>)\n<ul class=\"wp-block-list\">\n<li>Create a&nbsp;<strong>free trial<\/strong>&nbsp;account on the PostgreSQL cloud&nbsp;<a href=\"https:\/\/aiven.io\/\">https:\/\/aiven.io<\/a><\/li>\n\n\n\n<li>Create a PostgreSQL instance&nbsp;<\/li>\n\n\n\n<li>Access from Python<\/li>\n\n\n\n<li>Open in Colab the following GIST: <a href=\"https:\/\/gist.github.com\/gevargas\/71e5fc54a6f8f002a5fbe63974d02837\">https:\/\/gist.github.com\/gevargas\/71e5fc54a6f8f002a5fbe63974d02837<\/a><\/li>\n\n\n\n<li>Use the connection information provided by your Aiven instance.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading has-medium-font-size\">Write and test the following queries<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">1) Peek at the first five rows of the&nbsp;customers&nbsp;table.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2) Show each customer\u2019s full name and the year they joined (created_at).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3) Find all customers from France (country=&#8217;FR&#8217;).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4) List the newest customers, skipping the most recent one and taking the next two.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5) Find all customer emails containing&nbsp;&#8216;shop&#8217;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">6) List European customers (FR, ES, PT, DE) ordered alphabetically by country.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">7) Show all employees with their titles using&nbsp;COALESCE&nbsp;if missing<a href=\"applewebdata:\/\/69F77F17-4E3A-4DC7-B5E7-D1CF2BBBAE82#_ftn2\"><sup>[2]<\/sup><\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">8) Count how many orders exist and how many distinct ship countries appear.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">9) Count customers per country.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">10) Show only countries having at least two customers (HAVING).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">11) Display all orders with the customer\u2019s full name and ship country.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">12) List customers who have never placed an order.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">13) Compute the line total for each order item including discount.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">14) Show each order with its total revenue (sum of order items).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">15) List products that were never ordered.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">16) Find customers who have placed at least one order (EXISTS).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">17) List orders placed in the last 30 days relative to&nbsp;now().<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">18) Compare&nbsp;UNION&nbsp;and&nbsp;UNION ALL&nbsp;results for customer and order countries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">19) Find all products with names containing &#8216;t-shirt&#8217; (case-insensitive).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">20) Show all products and mark whether each is discontinued.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Tip: Run your queries step-by-step and verify using COUNT(*) to estimate result sizes.<\/em><em><\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"applewebdata:\/\/69F77F17-4E3A-4DC7-B5E7-D1CF2BBBAE82#_ftnref1\"><sup>[1]<\/sup><\/a>&nbsp;Legend: PK = Primary Key, FK = Foreign Key, UNIQUE = Unique constraint.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"applewebdata:\/\/69F77F17-4E3A-4DC7-B5E7-D1CF2BBBAE82#_ftnref2\"><sup>[2]<\/sup><\/a>&nbsp;<code><strong>COALESCE<\/strong><\/code>&nbsp;is a&nbsp;<strong>function that returns the first non-NULL value<\/strong>&nbsp;in a list of expressions.<br>SELECT COALESCE(NULL, NULL, &#8216;Hello&#8217;, &#8216;World&#8217;);&nbsp;\uf0e0&nbsp;\u2018Hello\u2019<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Aurora SQL Warm-up \u2014 Student Worksheet Individual work Context This worksheet accompanies the SQL warm-up dataset (classic retail schema) and is intended to support the expression of OLAP queries in a separate exercise. Objective:&nbsp;Practise basic SQL syntax, filtering, joins, grouping, &hellip; <a href=\"https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/sql-madness-getting-ready-for-big-challenges\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":11,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-83","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-json\/wp\/v2\/pages\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":5,"href":"https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-json\/wp\/v2\/pages\/83\/revisions"}],"predecessor-version":[{"id":138,"href":"https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-json\/wp\/v2\/pages\/83\/revisions\/138"}],"wp:attachment":[{"href":"https:\/\/vargas-solar.com\/data-ware-lake-houses-bi\/wp-json\/wp\/v2\/media?parent=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}