Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
145 views
Northwind Queries pt3
queries
Uploaded by
AndersonOliveira
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save northwind queries pt3 For Later
Download
Save
Save northwind queries pt3 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
145 views
Northwind Queries pt3
queries
Uploaded by
AndersonOliveira
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save northwind queries pt3 For Later
Carousel Previous
Carousel Next
Save
Save northwind queries pt3 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 4
Search
Fullscreen
2104/2020 GeeksEngine.com Knowledge Base Safe Computing Hosting Matters Computer Help Webmaster Help Intemet Marketing Web Development WAMP & LAMP MS Access Database SQL MySQL Tutorials Prorequisites Database Design (6) Sample Database Basic Select (12) Single Row Fune (9) Muts-table Select Subqueres (9) Summarize D2ta (5) Manipulate Data (2+) Managing Tables (3) Problem Solving (7) Geekstngine is hosted by HostGator, MySQL Noxthwind Queries - Part 3 Selecioneo idioma Pomeroy GosleTradutor Custom Search MySQL Northwind Queries - Part 3 This is part 3 of the tutorial series - converting the popular Microsoft Access Northwind database to MySQL. queries. ‘These queries are originated from Access Northwind Traders application. Some of them are relatively complex aggregated queries with sub-queres. 11. Products Above Average Price This query shows how to use sub-query to get a single value (average unit price) that can be used in the outer-query. select distinct Produetnane, UnttPriee ‘Fron Products lihere UnitPrice > (select avg(untterice) fron Products) (der by untzPrice; Here is the query result, 25 records returned. Janie omasinecten a2 Jaueso manchega La Pastore | Worsheoods Cranberry Sauce a 12. Product Sales for 1997 ‘This query shows how to group categories and products by quarters and shows sales amount for each quarter. select distinct a,categoryNane, .roductnane, Fornat(sun(e.UnitPrice * <.quantity * (1 - <.Discount)), 2) as Productsales, coneat(‘Qtr *, quarter(d.ShippedDate)) 2s ShippedQuarter ‘fron Categortes a nner join Produets b on a.CategoryIO = b.categoryI0 nner Join Order petaiie ¢ on beProdvctID = eProductIO ‘inner Join Orders aon d.OrderID = c.Onders0 Where .Shippedbate between date(" 1997-01-81") and date("1997-12-32") Group by a.categoryNane, '.ProductNane, coneat ("Qtr ", quarter(4.shippeddate) onder by a.categoryNane, ‘b.producthane, Shippedguarters hitps:iwwn.geeksengine.comidatabase!problem:-solving/nartuind-querias-par-3 php 1“2104/2020 MySQL Nosthwind Queries - Part 3 Here Is the query result. 286 records returned. siawpeamuseter, nat 105.0 tet cha 78.00 ter —— Che 1Anso the — hms 2iizes0 the eee hang 27a0.a0 tte ae hang 228.00 te fee hens 20sL.so tte eererases Cheng 2028.25 ote — pertreuge ceeze su20 tee Jeevsxace mareceuse weece ppazaed ce 413. Category Sales for 1997 ‘This query shows sales figures by categories - mainly just aggregation with sub-query. The inner query aggregates to product level, and the outer query further aggregates the result set rom inner-query to category level. select category, formt(sia(Prowetsales), 2) a5 Cateporysales “ select distinct a.categoryiane, b. Proaucthane, ‘Format (sun(e.UnitPrice * c.quantity * (1 - c.Discount)), 2) as Productsales, oncat( "Gtr ©, quarter(d.ShippedDate)) 2s Shippedguarter fron Categories a6 2 nner join Products 25 b on a.CategorylD ~ b.Category10 liner join Order petails a5 € on bebroguct1D = e,ProductIO {nner join Orders. 3s on é.0rderID = e-Oederi0 uinere dShippeabate between date('1997-61-@1") and date('1997-12-31") troup by a.categorynane, .Proauctnane, conese( Ger", quarter(d.Shippeddate)) onder by a.categoryNane, b.Producthane, Shippedguarter ) asx [roup by Categorynane ‘onder by €ategorynane; Here is the query result, B records returned, aos Jevesases prea. Jeencecrions 13,010.22 Jixeina/Cerenls _11,S11.15 14. Quarterly Orders by Product This query shows how to convert order dates to the corresponding quarters. It also demonstrates how SUM function is, Used together with CASE statement to get sales for each quarter, where quarters are converted from OrderDate columa select a.Prosuctane, ‘4.conpanyNane, year(OederDate) as Ordervear, Fornat(sun(ease quarter(e.Orderoate) when °1" then b.UnisPricerb.Quantity*(2-b-Discount) else @ end), @) “ote 2°, Fornat(sun(case quarcer(e.orderoate) when "2 then b,UniePrice®b.Quantity*(s-b.Discount) else 6 end), @) “Gtr 2°, format(sungense quarcer(e-Orderoate) when "3 ‘then b.UniePnicerd-Quantsty*(s-b.Discount) else @ end), @) “Qe 3°, Fornat(sun(case quarzer(e.orderoate) when "a ‘then b.Uniepricerb-Quantity*(2-B-Discount) else @ end), 9) “Gtr 4” ‘fron Progucte. ‘inner josn Order_Detafls b on a.ProductiD = b.Praducti9| inner Join Orders c on €.OrderID = b.OrderiD inner join Costowers on d-Custoneri0 = CustomerID whore €.Orderoate between date("%957-01-01") and date(‘3997~12-31") group by a.ProductNane, ‘.cenpanytsne, year(OrderDate) onder by a.ProductNane, ¢.Companyane; hitps:iwwn.geeksengine.comidatabase!problem:-solving/nartuind-querias-par-3 php 2182104/2020 MySQL Nosthwind Queries - Part 3 Here ts the query result. 947 records returned. etna [Compangten fatice micron —Juscente noreuo Taquecta orton Goase Cocina Tipise soe Micron Ratclesuaxe Canyon Grocery 15. Invoice [sesertear [oer ifote aJotr 3 | oe {A simple query to get detailed information for each sale so that invoice can be issued, select distinct b.Shiplane, b.shipadcress, bishipeity, Bi shipRegton, bi shippostalCoae, bishipcountey, bicustonersD, Cceompanytiane, eladaress, ecctty, e.negion, elbostaleode, leauntry, Concat(dsFinstNane, b.oraers0, blorderoste, b Requireabate, b.shippeadate, conpanytsne, e-preaucerD, Foreductnane, elunstirice, quantity, feibiscount, boresgne ‘fron Shippers a nner join Products # os F.ProduetIO fonder By b.Shiplane; inner jotn Orders b on a.ShippersD = b.Shipvia inner Join Costoners ¢ on e-CustonerI9 = 0-CustonerID inner Join Enployees d on d-tmployeeTO = .FxployeetD nner Join Order-betaiis «on b.OrderID = e.OrderIb ecraduct iD "*, dstastnane) as salesperson, f.UnitPnice * e.quantity * (1 - e.Discount) as ExtendedPrice, Here is the query eesut, 2,155 records returned, snupreseaicoae faiteeds Potcerkaote there Sex. 6? eelin a Teuiiiio Euparetsiavda, 42 14 Compcituciin 2222 Mexico D.Ps na Tey}iiio Fuparetsiavda, de 1a coustituciin 2222 xexico D.F. a Tesjille Baparedeiivda, de 1 Conetituciin 2222 México DLP. Jina TeujiLlo Enpaved ada. de La Cenarstacien 2222 Maaco DP Joon Texgilo Enporedes ada. de Ia Conatstarion 2222 Mexioo DoF. 16. Number of units in stock by category and supplier continent aan nsoat ‘This query shows that case statement is used in GROUP BY clause to lst the number of units in stack for each product category and supplier's continent, Note thet, i only s.Country (not the case statement) is used in the GROUP BY, Guplcated rows will exist for each product category and supplier continent. select e.category case when ‘hen Then else end $5" sun(o. Un fron Suppliers 5 inner Join Produ inner join Catep Wane as “Product Category", "feeauntry in (COCs Spain", "sweden*, ‘Genmany", "Norway", "Dentark’, Netherlands", "Fanand’,"Ttaly","France’) Europe s.country in (USA, "Canada" Brazil") ‘aneries” ‘Rebasacific! supplier Continent’ sitsinstock) 25 UnitsInstock jets p on p.SupplierIDes.SupphierID ies ¢ on e.CategoryT0up. category 0 hitps:iwwn.geeksengine.comidatabase!problem:-solving/narthuind-queras-par-3 php 3a2104/2020 No portion may be reprocuced without my writen permission, Software and hardware names mentioned on this ste are registered trademarks oftheir respective companies. Shoulé any nght Be infringed, is totaly unintentional. "op m2 an-ermal and Twill promptly and glaaly recy i MySQL Nosthwind Queries - Part 3 group by e.categoryvane, ase uhen country in (COUR "Spade" "Skeden’, “Germany” "NorHay" ‘Dennark', "Netherlands", Finland’, Tealy", France") then "Europe" hen s.country tn (°USA', "Canada, then ‘arerdea” else ‘Asia-Pacific’ antl’) ends Here is the query result. 21 records returnes. [unitoiastane feverases asieracitic a2 Jeoncecriona acta tacntic a Jroxtecrions Perope 34 Jexetne/ereais race Here comes the end of this article series. hope you find it useful in your day-to-day jab of SQL coding! Don't forget to download the full Script which can be found at the beginning ofthe frst two parts ofthis article series. Other tutorials in this category 1. MySQL Nonthwind Queries - Part 1 2. MySQL No-thwind Queries - Part 2 3 x “ 4. How to Fll Gaps in Sales Dat 1% 5, How to Calculate Totals, Subtotals and Grand Total 6. How to Work with NULL valves Back to Tutorial Index Page Copyright © 2020 Geekstngine.com. All Rights Reserved. ‘This website is hosted by HostGator. Home | Feedback | Terms of Use | Privacy Policy hitps:iwwn.geeksengine.comidatabase!problem:-solving/nartuind-querias-par-3 php ais
You might also like
Designing The Star Schema Database
PDF
No ratings yet
Designing The Star Schema Database
15 pages
Chapter 3 - SQL Notes
PDF
No ratings yet
Chapter 3 - SQL Notes
25 pages
SQL - 05 - Window Functions
PDF
No ratings yet
SQL - 05 - Window Functions
20 pages
T-SQL Northwind Database
PDF
100% (1)
T-SQL Northwind Database
52 pages
Assignment 3
PDF
No ratings yet
Assignment 3
2 pages
Delphi - Database Desktop Users Guide PDF
PDF
No ratings yet
Delphi - Database Desktop Users Guide PDF
171 pages
Answers To 50 Northwind Practice Queries Using MySQL
PDF
No ratings yet
Answers To 50 Northwind Practice Queries Using MySQL
6 pages
Chapter 1. Getting Started: Copying The Northwind Sample Database
PDF
No ratings yet
Chapter 1. Getting Started: Copying The Northwind Sample Database
10 pages
Exercise 15
PDF
No ratings yet
Exercise 15
7 pages
Query Practice Using Northwind
PDF
No ratings yet
Query Practice Using Northwind
1 page
Lab Manual Week 03
PDF
100% (1)
Lab Manual Week 03
4 pages
Northwind Database
PDF
No ratings yet
Northwind Database
9 pages
Chapter 9 MySQL
PDF
No ratings yet
Chapter 9 MySQL
29 pages
Lab 4 Lab SQL Northwind Sol
PDF
No ratings yet
Lab 4 Lab SQL Northwind Sol
3 pages
SQL Basic
PDF
No ratings yet
SQL Basic
33 pages
MySQL Tutorial - MySQL by Examples For Beginners
PDF
No ratings yet
MySQL Tutorial - MySQL by Examples For Beginners
39 pages
NorthwindQueries AnswersTo7and9
PDF
0% (1)
NorthwindQueries AnswersTo7and9
5 pages
NorthWind Database Relationships
PDF
No ratings yet
NorthWind Database Relationships
2 pages
ClientDataSet in Detail1
PDF
No ratings yet
ClientDataSet in Detail1
6 pages
Previous Next
PDF
No ratings yet
Previous Next
8 pages
SQL Server Replication
PDF
No ratings yet
SQL Server Replication
8 pages
Practice Questions DB
PDF
100% (1)
Practice Questions DB
10 pages
RDMS Notes
PDF
100% (1)
RDMS Notes
11 pages
SQL Queries For Practice
PDF
No ratings yet
SQL Queries For Practice
3 pages
SQL Database
PDF
No ratings yet
SQL Database
60 pages
Coding Horror - A Visual Explanation of SQL Joins
PDF
No ratings yet
Coding Horror - A Visual Explanation of SQL Joins
19 pages
SQL Joins: Database HND
PDF
No ratings yet
SQL Joins: Database HND
13 pages
Database Systems Introduction to Databases and Data Warehouses 2nd Edition Nenad Jukić - The ebook with all chapters is available with just one click
PDF
100% (2)
Database Systems Introduction to Databases and Data Warehouses 2nd Edition Nenad Jukić - The ebook with all chapters is available with just one click
47 pages
SQL Statements: To - Char To - Date Year STR - To - Date Datepart
PDF
100% (1)
SQL Statements: To - Char To - Date Year STR - To - Date Datepart
41 pages
MySQL Security Best Practices
PDF
No ratings yet
MySQL Security Best Practices
6 pages
MySQL Cursors
PDF
No ratings yet
MySQL Cursors
13 pages
Dms Lab Manual Updated
PDF
No ratings yet
Dms Lab Manual Updated
87 pages
SQL
PDF
33% (3)
SQL
20 pages
Relational Databases ASSIGNMENT - 2: Name: Kapila Ravichandran Student ID: 8918716 Section: 2
PDF
No ratings yet
Relational Databases ASSIGNMENT - 2: Name: Kapila Ravichandran Student ID: 8918716 Section: 2
3 pages
Entity Relationship Model PDF
PDF
100% (2)
Entity Relationship Model PDF
37 pages
Linux For You-Dec-2009
PDF
100% (1)
Linux For You-Dec-2009
116 pages
Unit 1-Chapter 3 - Classes, Objects and Methods
PDF
No ratings yet
Unit 1-Chapter 3 - Classes, Objects and Methods
36 pages
Answer EX 1
PDF
No ratings yet
Answer EX 1
12 pages
Query 1:: Unique Liquor Stores in Iowa
PDF
No ratings yet
Query 1:: Unique Liquor Stores in Iowa
3 pages
Learn SQL - Know Everything About SQL
PDF
100% (1)
Learn SQL - Know Everything About SQL
220 pages
Db2 SQL Query
PDF
No ratings yet
Db2 SQL Query
188 pages
DBMS Assignment
PDF
100% (1)
DBMS Assignment
7 pages
Mysql Queries
PDF
No ratings yet
Mysql Queries
9 pages
SQLsecrets Revealed
PDF
No ratings yet
SQLsecrets Revealed
103 pages
MySQL Presentation
PDF
100% (2)
MySQL Presentation
39 pages
A Simple CRUD Tutorial Using Java Servlet
PDF
No ratings yet
A Simple CRUD Tutorial Using Java Servlet
18 pages
SQL3
PDF
No ratings yet
SQL3
6 pages
Monitor
PDF
100% (1)
Monitor
22 pages
Query Skills Demo Using Northwind Database
PDF
No ratings yet
Query Skills Demo Using Northwind Database
4 pages
Crystal Reports Introductory
PDF
No ratings yet
Crystal Reports Introductory
124 pages
Sql-Data Types
PDF
No ratings yet
Sql-Data Types
15 pages
MIS 310 Tutorial
PDF
No ratings yet
MIS 310 Tutorial
31 pages
Working With Triggers in A MySQL Database PDF
PDF
No ratings yet
Working With Triggers in A MySQL Database PDF
10 pages
Oops Through Java Lab Manual - R22
PDF
No ratings yet
Oops Through Java Lab Manual - R22
77 pages
SQL Concepts - Tuning PDF
PDF
No ratings yet
SQL Concepts - Tuning PDF
561 pages
Structured Query Language
PDF
No ratings yet
Structured Query Language
26 pages
SQL Cheat Sheet - Follow Dr. AngShuMan Ghosh For More-1
PDF
No ratings yet
SQL Cheat Sheet - Follow Dr. AngShuMan Ghosh For More-1
3 pages
Nort Wind Que Ary SSF
PDF
No ratings yet
Nort Wind Que Ary SSF
9 pages
Unit 3 SQL
PDF
No ratings yet
Unit 3 SQL
72 pages
Lecture 4: More SQL: Monday, January 13th, 2003
PDF
No ratings yet
Lecture 4: More SQL: Monday, January 13th, 2003
58 pages
Hotel ER Diagram
PDF
No ratings yet
Hotel ER Diagram
1 page
14th International Conference On Information Technology: New Generations (ITNG 2017)
PDF
No ratings yet
14th International Conference On Information Technology: New Generations (ITNG 2017)
16 pages
Xiro Gian No Poulos
PDF
No ratings yet
Xiro Gian No Poulos
13 pages
Modeling Relational Data As Graphs For Mining
PDF
No ratings yet
Modeling Relational Data As Graphs For Mining
6 pages
Migration of Data From Relational Database To Graph Database
PDF
No ratings yet
Migration of Data From Relational Database To Graph Database
6 pages
Insignias LOP MA
PDF
No ratings yet
Insignias LOP MA
1 page
A Genetic Algorithm For Database Query Optimization: February 1970
PDF
No ratings yet
A Genetic Algorithm For Database Query Optimization: February 1970
9 pages