תרגול מספר 10 מעבדת SQL מספר 3

Slides:



Advertisements
Similar presentations
SQL-week5-1 In-Class Exercise Answer IST 210 Organization of Data IST2101.
Advertisements

TURKISH STATISTICAL INSTITUTE 1 /34 SQL FUNDEMANTALS (Muscat, Oman)
SQL Sub (or Nested ) Query. Examples Q: Find students whose GPA is below the average. –The criteria itself requires a SQL statement. –SELECT * FROM student.
SQL (2).
Chapter 11 Group Functions
CSEN 5314 Quiz What type of join is needed when you wish to include rows that do not have matching values? A. Equi-joinB. Natural join C. Outer.
Sub Queries Pertemuan 5 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Nov 24, 2003Murali Mani SQL B term 2004: lecture 12.
Murali Mani SQL. Murali Mani SELECT-FROM-WHERE SELECT * FROM Student WHERE sName=“Greg” AND address=“320 FL”  (sName=“Greg” AND address=“320 FL”) (Student)
--The SQL Query Language DML--1 LIKE  LIKE allows to select character strings which have some element in common by using wild cards:  Wild cards:  “%”
1 Rewriting Intersect Queries Using In SELECT S.sid FROM Sailors S, Boats B, Reserves R WHERE S.sid = R.sid and R.bid = B.bid and B.color = ‘red’ INTERSECT.
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
SQL Queries and Subqueries Zaki Malik September 04, 2008.
Access Path Selection in a Relational Database Management System Selinger et al.
Using Special Operators (LIKE and IN)
Week 10 Quiz 9 Answers Group 28 Christine Hallstrom Deena Phadnis.
Unit 4 Queries and Joins. Key Concepts Using the SELECT statement Statement clauses Subqueries Multiple table statements Using table pseudonyms Inner.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Programming in R SQL in R. Running SQL in R In this session I will show you how to: Run basic SQL commands within R.
Data Manipulation 21 After this lecture, you should be able to:  Use SQL SELECT statement effectively to retrieve the data from multiple related tables.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
Indexes and Views Unit 7.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
1 IT420: Database Management and Organization SQL part 3 7 February 2006 Adina Crăiniceanu
SQL Select Statement IST359.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
IFS180 Intro. to Data Management Chapter 11 - Subqueries.
1/18/00CSE 711 data mining1 What is SQL? Query language for structural databases (esp. RDB) Structured Query Language Originated from Sequel 2 by Chamberlin.
SQL-5 In-Class Exercise Answer IST 210 Organization of Data IST2101.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
ORT Braude, CSE 61309, ©2004 Gary Schloss Exam Question #1: ER, RA & SQL Consider a DB schema with the following relations: - Student (s#, sname) - Professor.
1 SQL – IV Grouping data from tables in SQL –The concept of grouping –GROUP BY clause –HAVING Clause –Determining whether values are unique –Group by using.
Subqueries.
SQL Miscellaneous Topics. Views A database view is: – a virtual or logical table based on a query. – a stored query. CREATE VIEW viewname AS query; –CREATE.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
In this session, you will learn to: Query data by using joins Query data by using subqueries Objectives.
Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: ID, P1, P2, P3 1.Display the.
1 Schema for Student Registration System Student Student (Id, Name, Addr, Status) Professor Professor (Id, Name, DeptId) Course Course (DeptId, CrsCode,
SQL: Structured Query Language Instructor: Mohamed Eltabakh 1 Part II.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Slide 1 of 32ASH-Training Querying and Managing Data Using SQL Server 2014 By: Segla In this session, you will learn to: Query data by using joins Query.
Create Stored Procedures and Functions Database Management Fundamentals LESSON 2.4.
SQL Reminder Jiankang Yuan Martin Lemke. SQL Reminder - SELECT SELECT column_name1, column_name2, … FROM table_name SELECT * FROM table_name.
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
$200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 $200.
IFS180 Intro. to Data Management Chapter 10 - Unions.
Eugene Meidinger Intermediate Querying: Going Beyond Select
Structured Query Language
Chapter 12 Subqueries and MERGE Oracle 10g: SQL
SQL : Query Language Part II CS3431.
Recursion in SQL Nonlinear and Mutual Recursion.
پايگاه داده ها.
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
SQL – Entire Select.
Chapter 4 Summary Query.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
SQL: Structured Query Language
SQL Fundamentals in Three Hours
Instructor: Mohamed Eltabakh
This shows the tables that I made for the order system.
CMPT 354: Database System I
SQL: Structured Query Language
Subqueries.
Aggregate Functions.
LINQ to SQL Part 3.
SQL.
SQL: Structured Query Language
Presentation transcript:

תרגול מספר 10 מעבדת SQL מספר 3 בסיסי נתונים תרגול מספר 10 מעבדת SQL מספר 3

הנושאים לתרגול Basic SELECT statements Join Aggregation Order by Top Subqueries

Subquery Output Types Single Value Single Column Table בכל מקום בו יכול להופיע ביטוי, ניתן להשתמש במקומו בתת-שאילתא שמחזירה ערך בודד. לדוגמה: SELECT sname [Ship Name], max_speed [Max Speed] FROM Ships WHERE max_speed > שלוף את שמות החיזרים בעלי מספר הרגליים הנמוך ביותר "Speed Delta" מוגדר כַּהפרש בין מהירות חללית מסוימת למהירות החללית המהירה ביותר בצי, הצג את הדלתא עבור כל חללית (SELECT AVG(max_speed) FROM Ships) 90

Referencing the Outer Query Subquery Output Types Single Value Single Column Table Referencing the Outer Query נניח שנרצה לדעת עבור כל כוכב לכת את החללית המהירה ביותר שהגיעה אליו: SELECT pname [Planet], sname [Fastest Ship] FROM dbo.Planets p JOIN dbo.Trips t ON p.p_no = t.p_no JOIN dbo.Ships s ON t.s_no = s.s_no WHERE max_speed = ( SELECT MAX(max_speed) FROM dbo.Trips t1 JOIN dbo.Ships s1 ON t1.s_no = s1.s_no WHERE t1.p_no = p.p_no)

Subquery Output Types Single Value Single Column Table ניתן להשתמש בתת-שאילתא שמחזירה עמודה בודדת בסעיף WHERE במספר אופנים: SELECT pname [Planet] FROM dbo.Planets p JOIN dbo.Trips t ON p.p_no = t.p_no JOIN dbo.Aliens_in_trips at ON t.t_no = at.t_no WHERE id_no IN (SELECT id_no FROM dbo.Aliens_in_trips GROUP BY id_no HAVING COUNT(*) = 1) מה עושה השאילתא? שלוף את שמות כוכבי הלכת בהם ביקרו חייזרים בעלי יותר מ- 5 רגליים שביקרו בלפחות שלושה כוכבי לכת שונים * IN IN ANY ALL

Subquery Output Types Single Value Single Column Table ניתן להשתמש בתת-שאילתא שמחזירה עמודה בודדת בסעיף WHERE במספר אופנים: SELECT pname [Planet] FROM dbo.Planets p JOIN dbo.Trips t ON p.p_no = t.p_no JOIN dbo.Aliens_in_trips at ON t.t_no = at.t_no WHERE id_no = ANY (SELECT id_no FROM dbo.Aliens_in_trips GROUP BY id_no HAVING COUNT(*) = 1) שלוף את שמות כל החלליות שמהירוֹת יותר מלפחות חללית אחת בעלת פחות מושבים IN ANY ALL

Subquery Output Types Single Value Single Column Table ניתן להשתמש בתת-שאילתא שמחזירה עמודה בודדת בסעיף WHERE במספר אופנים: פועל בדיוק כמו ANY רק עבור כל הרשומות בתת-השאילתא שלוף את שמות כוכבי הלכת שהכי גדולים במערכת השמש שלהם (ניתן לביצוע בלי אגרגציה) IN ANY ALL

Subquery Output Types ניתן להשתמש בתת-שאילתא שמחזירה טבלה בשתי צורות: Single Value Single Column Table ניתן להשתמש בתת-שאילתא שמחזירה טבלה בשתי צורות: SELECT pname [Planet] FROM dbo.Planets p WHERE NOT EXISTS(SELECT * FROM dbo.Aliens a JOIN dbo.Aliens_in_trips at ON a.id_no = at.id_no JOIN dbo.Trips t ON at.t_no = t.t_no WHERE t.p_no = p.p_no AND no_of_legs > 5) מה עושה השאילתא? EXISTS EXISTS As table

Subquery Output Types ניתן להשתמש בתת-שאילתא שמחזירה טבלה בשתי צורות: Single Value Single Column Table ניתן להשתמש בתת-שאילתא שמחזירה טבלה בשתי צורות: ניתן לכתוב תת-שאילתא בשדה ה- FROM והתוצאה תתנהג כמו טבלה מצא, עבור כל חללית, את ממוצע מספר הרגליים המקסימאלי שהיה לחייזר שטס בה במסע מסוים האם התוצאה נכונה? CAST(expression AS <data_type>) EXISTS As table