{"id":184831,"date":"2025-01-21T17:07:04","date_gmt":"2025-01-21T17:07:04","guid":{"rendered":"https:\/\/learnexams.com\/blog\/?p=184831"},"modified":"2025-01-21T17:07:06","modified_gmt":"2025-01-21T17:07:06","slug":"write-a-sql-query-to-find-all-the-invoices-for-customer-56-and-58-where-the-total-was-between-1-00-and-5-00","status":"publish","type":"post","link":"https:\/\/www.learnexams.com\/blog\/2025\/01\/21\/write-a-sql-query-to-find-all-the-invoices-for-customer-56-and-58-where-the-total-was-between-1-00-and-5-00\/","title":{"rendered":"Write a SQL query to find all the invoices for customer 56 and 58 where the total was between $1.00 and $5.00"},"content":{"rendered":"\n<p>Write a SQL query to find all the invoices for customer 56 and 58 where the total was between $1.00 and $5.00. 5. Write a SQL query to find all the tracks whose name starts with &#8216;All&#8217;. 6. Write a SQL query to find all the customer emails that start with &#8220;J&#8221; and are from gmail.com. 7. Write a SQL query to find all the invoices from the billing city Bras\u00c3\u0192\u00c2\u00adlia, Edmonton, and Vancouver and sort in descending order by invoice ID. 8. Write a SQL query to show the number of orders placed by each customer (hint: this is found in the invoices table) and sort the result by the number of orders in descending order. 9. Write a SQL query to find the albums with 12 or more tracks.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/learnexams.com\/blog\/wp-content\/uploads\/2025\/01\/image-363.png\" alt=\"\" class=\"wp-image-184832\"\/><\/figure>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-6-color\"><strong>The Correct Answer and Explanation is :<\/strong><\/mark><\/p>\n\n\n\n<p>Here are the SQL queries and explanations for each of your tasks:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Queries:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Tracks with a length of 5,000,000 milliseconds or more:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   SELECT * \n   FROM tracks \n   WHERE milliseconds &gt;= 5000000;<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Invoices with total between $5 and $15:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   SELECT * \n   FROM invoices \n   WHERE total BETWEEN 5 AND 15;<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Customers from specific states:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   SELECT * \n   FROM customers \n   WHERE state IN ('RJ', 'DF', 'AB', 'BC', 'CA', 'WA', 'NY');<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Invoices for customers 56 and 58 with total between $1.00 and $5.00:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   SELECT * \n   FROM invoices \n   WHERE customer_id IN (56, 58) \n     AND total BETWEEN 1.00 AND 5.00;<\/code><\/pre>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li><strong>Tracks whose name starts with &#8216;All&#8217;:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   SELECT * \n   FROM tracks \n   WHERE name LIKE 'All%';<\/code><\/pre>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li><strong>Customer emails starting with &#8216;J&#8217; and from Gmail:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   SELECT * \n   FROM customers \n   WHERE email LIKE 'J%@gmail.com';<\/code><\/pre>\n\n\n\n<ol start=\"7\" class=\"wp-block-list\">\n<li><strong>Invoices from specific cities, sorted descending by invoice ID:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   SELECT * \n   FROM invoices \n   WHERE billing_city IN ('Bras\u00edlia', 'Edmonton', 'Vancouver') \n   ORDER BY invoice_id DESC;<\/code><\/pre>\n\n\n\n<ol start=\"8\" class=\"wp-block-list\">\n<li><strong>Number of orders per customer, sorted descending:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   SELECT customer_id, COUNT(*) AS order_count \n   FROM invoices \n   GROUP BY customer_id \n   ORDER BY order_count DESC;<\/code><\/pre>\n\n\n\n<ol start=\"9\" class=\"wp-block-list\">\n<li><strong>Albums with 12 or more tracks:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   SELECT album_id \n   FROM tracks \n   GROUP BY album_id \n   HAVING COUNT(*) &gt;= 12;<\/code><\/pre>\n\n\n\n<ol start=\"10\" class=\"wp-block-list\">\n<li><strong>Number of albums by Led Zeppelin:<\/strong> <code>SELECT COUNT(*) AS album_count FROM albums JOIN artists ON albums.artist_id = artists.artist_id WHERE artists.name = 'Led Zeppelin';<\/code><\/li>\n\n\n\n<li><strong>List of album titles and unit prices for Audioslave:<\/strong> <code>SELECT albums.title, tracks.unit_price FROM albums JOIN artists ON albums.artist_id = artists.artist_id JOIN tracks ON albums.album_id = tracks.album_id WHERE artists.name = 'Audioslave';<\/code><\/li>\n\n\n\n<li><strong>Customers without an invoice:<\/strong> <code>SELECT first_name, last_name FROM customers WHERE customer_id NOT IN (SELECT DISTINCT customer_id FROM invoices);<\/code><\/li>\n\n\n\n<li><strong>Total price for each album:<\/strong><br><code>sql SELECT albums.title, SUM(tracks.unit_price) AS total_price FROM albums JOIN tracks ON albums.album_id = tracks.album_id GROUP BY albums.title;<\/code><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Why order matters:<\/strong> The database must be set up in the correct sequence to respect dependencies. For example, tracks depend on albums, and albums depend on artists. If you attempt to query or insert data without establishing these relationships, errors may occur.<\/li>\n\n\n\n<li><strong>Query breakdown:<\/strong> Each SQL query demonstrates common database operations:<\/li>\n\n\n\n<li>Filtering with <code>WHERE<\/code> clauses (e.g., invoices, tracks).<\/li>\n\n\n\n<li>Aggregating data using <code>GROUP BY<\/code> and <code>HAVING<\/code> for counts or sums.<\/li>\n\n\n\n<li>Using joins to connect related tables for more complex queries (e.g., albums and artists).<\/li>\n\n\n\n<li>Sorting results with <code>ORDER BY<\/code> for clarity.<\/li>\n\n\n\n<li><strong>Insight:<\/strong> These queries highlight various SQL features, like filtering, sorting, aggregating, and joining, to extract meaningful data from a relational database efficiently. Queries like #8 and #13 showcase the power of SQL in summarizing and analyzing datasets for actionable insights.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Write a SQL query to find all the invoices for customer 56 and 58 where the total was between $1.00 and $5.00. 5. Write a SQL query to find all the tracks whose name starts with &#8216;All&#8217;. 6. Write a SQL query to find all the customer emails that start with &#8220;J&#8221; and are from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25],"tags":[],"class_list":["post-184831","post","type-post","status-publish","format-standard","hentry","category-exams-certification"],"_links":{"self":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/184831","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/comments?post=184831"}],"version-history":[{"count":0,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/184831\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/media?parent=184831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/categories?post=184831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/tags?post=184831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}