Database Design and Implementation

Slides:



Advertisements
Similar presentations
SLIDE 1IS Fall 2002 Database Design: Object- Oriented Modeling University of California, Berkeley School of Information Management and.
Advertisements

9/30/1999SIMS 257: Database Management -- Ray Larson SQL Commands University of California, Berkeley School of Information Management and Systems SIMS.
SLIDE 1IS 257 – Fall 2004 Database Design: Logical Model Design & Access DB Creation University of California, Berkeley School of Information.
9/7/1999Information Organization and Retrieval Database Design: Conceptual Model and ER Diagramming University of California, Berkeley School of Information.
SLIDE 1IS Fall 2002 Database Life Cycle and Introduction to Access University of California, Berkeley School of Information Management.
SLIDE 1IS 257 – Fall 2005 Database Life Cycle and Introduction to Access University of California, Berkeley School of Information Management.
Computer Science 101 Web Access to Databases SQL – Extended Form.
Chapter 3 Single-Table Queries
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Using Special Operators (LIKE and IN)
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
1 SQL II CIS*2450 Advanced Programming Concepts. 2 Data Types INTEGER –numbers without a decimal point –range is to SMALLINT –like.
1 Chapter 3 Single Table Queries. 2 Simple Queries Query - a question represented in a way that the DBMS can understand Basic format SELECT-FROM Optional.
Lab week 10 Aggregates and sub-queries And assignment details.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT395, Week 4 Database Design and ER Modeling This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT395, Week 12 Storage, Grid Computing, Review This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
INF1343, Winter 2011 Data Modeling and Database Design Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
INF1343, Week 6 Implementing a Database with SQL This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
CCT395, Week 11 Review, Permissions Physical Storage and Performance This presentation is licensed under Creative Commons Attribution License, v. 3.0.
CCT395, Week 6 Implementing a Database with SQL and a Case Study Exercise This presentation is licensed under Creative Commons Attribution License, v.
Database Design and Implementation
CCT395, Week 2 Introduction to SQL Yuri Takhteyev September 15, 2010
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
INF1343, Week 4 Database Design and ER Modeling This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT395, Week 5 Translating ER into Relations; Normalization This presentation is licensed under Creative Commons Attribution License, v To view a.
CCT395, Week 7 SQL with PHP This presentation is licensed under Creative Commons Attribution License, v To view a copy of this license, visit
INF1343, Winter 2011 Data Modeling and Database Design Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
SQL Query Getting to the data ……..
Database Design and Implementation
Translating ER into Relations; Normalization
Review Databases and Objects
Database Design: Conceptual Model and ER Diagramming
Lab 13 Databases and SQL.
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
Special Topics in CCIT: Databases
CCT1343, Week 2 Single-Table SQL Yuri Takhteyev University of Toronto
References: Text Chapters 8 and 9
Free and Open Source Software Today
Chapter 3 Introduction to SQL(3)
Applying the OSS Model to Other Domains
Finishing “Producing FOSS” Economics of Open Source
Finishing Economics, Moving onto Politics
Data Modeling and Database Design
More Economics of Open Source
Review of Main Database Features
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
Database Design and Implementation
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
SQL Structured Query Language 11/9/2018 Introduction to Databases.
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
SQL – Entire Select.
Chapter 4 Summary Query.
CMPT 354: Database System I
Section 4 - Sorting/Functions
Projecting output in MySql
Joins and other advanced Queries
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

Database Design and Implementation CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution License, v. 3.0. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/. This presentation incorporates images from the Crystal Clear icon collection by Everaldo Coelho, available under LGPL from http://everaldo.com/crystal/.

Week 9 Advanced Queries

What are the names of the Diveshop’s customers who paid cash for their orders? select DIVECUST.Name from DIVECUST join DIVEORDS on DIVECUST.Customer_No = DIVEORDS.Customer_No where DIVEORDS.PaymentMethod = "Cash";

How many customers paid cash for their orders? select count(distinct DIVECUST.Name) from DIVECUST join DIVEORDS on DIVECUST.Customer_No = DIVEORDS.Customer_No where DIVEORDS.PaymentMethod = "Cash";

select sum(VacationCost) from DIVEORDS where PaymentMethod = "Cash"; How much cash did all of them paid together (in cash)? select sum(VacationCost) from DIVEORDS where PaymentMethod = "Cash";

select sum(VacationCost) from DIVEORDS where PaymentMethod = "Visa"; And how much money was paid through Visa? select sum(VacationCost) from DIVEORDS where PaymentMethod = "Visa";

And how much money was paid through Master Card? select sum(VacationCost) from DIVEORDS where PaymentMethod = "Master Card";

Can we just get all the sums for each payment method at once? select PaymentMethod, sum(VacationCost) from DIVEORDS group by PaymentMethod;

Which payment method brought in most money? select PaymentMethod, sum(VacationCost) from DIVEORDS group by PaymentMethod order by sum(VacationCost) desc;

Which payment method brought in most money for vacations that involved 1 or 2 people? select PaymentMethod, sum(VacationCost) from DIVEORDS where No_Of_People <= 2 group by PaymentMethod order by sum(VacationCost) desc; Note: “where” before “group by”!

Which payment method was most popular for vacations that involved 1 or 2 people? select PaymentMethod, sum(VacationCost) from DIVEORDS where No_Of_People <= 2 group by PaymentMethod order by sum(VacationCost) desc limit 1;

Which payment method was most popular for vacations that involved 1 or 2 people and cost under $5000? select PaymentMethod, sum(VacationCost) from DIVEORDS where No_Of_People <= 2 and VacationCost < 5000 group by PaymentMethod order by sum(VacationCost) desc limit 1;

Which payment methods brought in more than $30,000 in total? select PaymentMethod, sum(VacationCost) from DIVEORDS group by PaymentMethod having sum(VacationCost) > 30000 order by sum(VacationCost) desc; Note the order!

Where vs Having where selects rows from the original table (after all the joins) having by selects rows from the aggregated table

Order of Clauses 7 1 2 3 4 5 6 select ... from … join … (several times) where … group by … having … order by … limit ...

Which payment methods brought in more than $15,000 on average per order? select PaymentMethod, avg(VacationCost) from DIVEORDS group by PaymentMethod having avg(VacationCost) > 15000;

What was the average amount coming from each payment methods for orders costing over $15,000? select PaymentMethod, avg(VacationCost) from DIVEORDS where VacationCost > 15000 group by PaymentMethod;

What about this query? select PaymentMethod, avg(VacationCost) from DIVEORDS where avg(VacationCost) > 15000 group by PaymentMethod; Invalid!

And this one? select PaymentMethod, avg(VacationCost) from DIVEORDS group by PaymentMethod having VacationCost > 15000; Invalid!

What payment methods were used for vacations costing above average? select avg(VacationCost) from DIVEORDS; select PaymentMethod from DIVEORDS where VacationCost > 18462.8 group by PaymentMethod;

What payment methods were used for vacations costing above average? set @avg_cost = ( select avg(VacationCost) from DIVEORDS); select PaymentMethod from DIVEORDS where VacationCost > @avg_cost group by PaymentMethod;

What payment methods were used for vacations costing above average? select PaymentMethod from DIVEORDS where VacationCost > ( select avg(VacationCost) from DIVEORDS) group by PaymentMethod; An “uncorrelated” subquery

What payment methods on average brought more money than the average for all vacations? select PaymentMethod, avg(VacationCost) from DIVEORDS group by PaymentMethod having avg(VacationCost) > ( select avg(VacationCost) from DIVEORDS); Still “uncorrelated”

Which vacations cost more than the average for their payment method? select PaymentMethod, VacationCost from DIVEORDS as O where VacationCost > ( select avg(VacationCost) from DIVEORDS PaymentMethod=O.PaymentMethod ); This is a “correlated” query!

Which categories of marine life have more than one species Which categories of marine life have more than one species? (Use BIOLIFE.) select Category, count(*) from BIOLIFE group by Category having count(*) > 1;

What are the smallest and the largest lengths in each of the categories that have more than 1 species? select Category, min(Length_cm), max(Length_cm) from BIOLIFE group by Category having count(*) > 1;

Which category with >1 species has the largest ratio between the largest and the smallest length of species? select Category, max(Length_cm) / min(Length_cm) from BIOLIFE group by Category having count(*) > 1; Step 1

Which category with >1 species has the largest ratio between the largest and the smallest length of species? select Category, max(Length_cm) / min(Length_cm) as Ratio from BIOLIFE group by Category having count(*) > 1; Step 2

Which category with >1 species has the largest ratio between the largest and the smallest length of species? select * from (select Category, max(Length_cm) / min(Length_cm) as Ratio from BIOLIFE group by Category having count(*) > 1) as Categories order by Categories.Ratio desc; Step 3

Questions?