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)
180 views
4 pages
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
Save
Save northwind queries pt3 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
180 views
4 pages
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
Carousel Previous
Carousel Next
Download
Save
Save northwind queries pt3 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save northwind queries pt3 For Later
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
Database Queries (MySql)
PDF
50% (2)
Database Queries (MySql)
112 pages
T-SQL Northwind Database
PDF
100% (1)
T-SQL Northwind Database
52 pages
SQL
PDF
33% (3)
SQL
20 pages
Query Optimization
PDF
100% (1)
Query Optimization
138 pages
Exercises On Northwind Database
PDF
29% (7)
Exercises On Northwind Database
2 pages
Structured Query Lang.
PDF
100% (1)
Structured Query Lang.
105 pages
Entity Relationship Model PDF
PDF
100% (2)
Entity Relationship Model PDF
37 pages
SQLsecrets Revealed
PDF
No ratings yet
SQLsecrets Revealed
103 pages
MariaDB - Introduction To MariaDB v1 6
PDF
No ratings yet
MariaDB - Introduction To MariaDB v1 6
30 pages
MySQL Presentation
PDF
100% (3)
MySQL Presentation
39 pages
SQL Concepts - Tuning PDF
PDF
No ratings yet
SQL Concepts - Tuning PDF
561 pages
Database Systems (Introduction)
PDF
100% (1)
Database Systems (Introduction)
39 pages
Delphi - Database Desktop Users Guide PDF
PDF
No ratings yet
Delphi - Database Desktop Users Guide PDF
171 pages
SQL Server Indexes
PDF
No ratings yet
SQL Server Indexes
14 pages
Db2 SQL Query
PDF
No ratings yet
Db2 SQL Query
188 pages
DBT SB
PDF
No ratings yet
DBT SB
159 pages
Data Versioning For Graph Databases
PDF
No ratings yet
Data Versioning For Graph Databases
71 pages
Lab 5. Databases. Introduction To SQL (CS Open CourseWare)
PDF
100% (1)
Lab 5. Databases. Introduction To SQL (CS Open CourseWare)
11 pages
Lab Manual Week 03
PDF
100% (1)
Lab Manual Week 03
4 pages
Mysql Queries
PDF
No ratings yet
Mysql Queries
9 pages
Sailors Reserves Boats
PDF
No ratings yet
Sailors Reserves Boats
4 pages
Answers To 50 Northwind Practice Queries Using MySQL
PDF
No ratings yet
Answers To 50 Northwind Practice Queries Using MySQL
6 pages
NorthwindQueries AnswersTo7and9
PDF
0% (1)
NorthwindQueries AnswersTo7and9
5 pages
Chapter 4
PDF
No ratings yet
Chapter 4
53 pages
Dms Lab Manual Updated
PDF
No ratings yet
Dms Lab Manual Updated
87 pages
Unit 3 SQL
PDF
No ratings yet
Unit 3 SQL
72 pages
MySQL Tutorial - MySQL by Examples For Beginners
PDF
No ratings yet
MySQL Tutorial - MySQL by Examples For Beginners
39 pages
Chapter 9 MySQL
PDF
No ratings yet
Chapter 9 MySQL
29 pages
Hotel ER Diagram
PDF
No ratings yet
Hotel ER Diagram
1 page
Database Lab
PDF
No ratings yet
Database Lab
57 pages
UD2 ER Model
PDF
No ratings yet
UD2 ER Model
46 pages
Structured Query Language
PDF
No ratings yet
Structured Query Language
26 pages
Unit 1-Chapter 3 - Classes, Objects and Methods
PDF
No ratings yet
Unit 1-Chapter 3 - Classes, Objects and Methods
36 pages
SQL Database
PDF
No ratings yet
SQL Database
60 pages
SQL Basic
PDF
No ratings yet
SQL Basic
33 pages
Practice Questions DB
PDF
100% (1)
Practice Questions DB
10 pages
Mysql Commands Notes
PDF
No ratings yet
Mysql Commands Notes
23 pages
Coding Horror - A Visual Explanation of SQL Joins
PDF
No ratings yet
Coding Horror - A Visual Explanation of SQL Joins
19 pages
DBMS Project
PDF
No ratings yet
DBMS Project
27 pages
Exercise 15
PDF
No ratings yet
Exercise 15
7 pages
MCS-043 Solved Assignments
PDF
No ratings yet
MCS-043 Solved Assignments
34 pages
Lecture3 - Relational Data Model and Relational Constraints
PDF
No ratings yet
Lecture3 - Relational Data Model and Relational Constraints
33 pages
ClientDataSet in Detail1
PDF
No ratings yet
ClientDataSet in Detail1
6 pages
NorthWind Database Relationships
PDF
No ratings yet
NorthWind Database Relationships
2 pages
Lecture Week 3-Databases
PDF
No ratings yet
Lecture Week 3-Databases
17 pages
Answer EX 1
PDF
No ratings yet
Answer EX 1
12 pages
Northwind Database
PDF
No ratings yet
Northwind Database
9 pages
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
SQL Server Replication
PDF
No ratings yet
SQL Server Replication
8 pages
Designing The Star Schema Database
PDF
No ratings yet
Designing The Star Schema Database
15 pages
Xiro Gian No Poulos
PDF
No ratings yet
Xiro Gian No Poulos
13 pages
Nort Wind Que Ary SSF
PDF
No ratings yet
Nort Wind Que Ary SSF
9 pages
BUS 464 Assignment 2
PDF
No ratings yet
BUS 464 Assignment 2
5 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
A Genetic Algorithm For Database Query Optimization: February 1970
PDF
No ratings yet
A Genetic Algorithm For Database Query Optimization: February 1970
9 pages
Spreadsheets Notes
PDF
100% (2)
Spreadsheets Notes
4 pages
"Data Warehouse and Data Mining": Institute of Management Studies
PDF
No ratings yet
"Data Warehouse and Data Mining": Institute of Management Studies
14 pages
Query 1:: Unique Liquor Stores in Iowa
PDF
No ratings yet
Query 1:: Unique Liquor Stores in Iowa
3 pages
Assignment Chapter 3 PDF
PDF
No ratings yet
Assignment Chapter 3 PDF
2 pages
Modeling Relational Data As Graphs For Mining
PDF
No ratings yet
Modeling Relational Data As Graphs For Mining
6 pages
SQL Queries For Practice
PDF
No ratings yet
SQL Queries For Practice
3 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
Lab 4 Lab SQL Northwind Sol
PDF
No ratings yet
Lab 4 Lab SQL Northwind Sol
3 pages
Interacting With Database Using MySQL
PDF
No ratings yet
Interacting With Database Using MySQL
4 pages
MySQL Security Best Practices
PDF
No ratings yet
MySQL Security Best Practices
6 pages
Query Skills Demo Using Northwind Database
PDF
No ratings yet
Query Skills Demo Using Northwind Database
4 pages
Insignias LOP MA
PDF
No ratings yet
Insignias LOP MA
1 page