Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 et al (1976) at IBM’s San Jose Research Lab. ANSI (American National Standards Institute) published an SQL standard in 1986

2 1/18/00CSE 711 data mining2 Role of SQL? Data Definition Language (DDL) Interactive data manipulation language (DML) Embeded data manipulation language View definition Integrity Transaction Control

3 1/18/00CSE 711 data mining3 Information Retrieval of SQL? The select clause is used to list the attributes desired in the result of a query (specifies the columns) The from clause lists the relations to be scanned in the evaluation of the expression (specifies the tables) The where clause consists of a predicate involving attributes of the relations that appear in the from clause. (specifies the rows) select A 1, A 2,..., A n from r 1, r 2,..., r m where p

4 1/18/00CSE 711 data mining4 Column Manipulation of SQL? Choosing Columns SELECT fname, salary FROM employee Rearranging the Order of Columns SELECT salary, fname FROM employee Insert Literals SELECT fname, ‘Salary: ’, salary FROM employee Changing Column Headings SELECT First_name = fname, salary FROM employee

5 1/18/00CSE 711 data mining5 Manipulating Data of SQL? Manipulating Numerical Data (Arithmetic op., Math. Func.) SELECT fname, (salary * 1.1) FROM employee Manipulating Character Data (String func.) SELECT SUBSTRING(fname,1,1), salary FROM employee Manipulating Datetime Data SELECT fname, birthdate, DATEDIFF(year, birthdate, getdate()) FROM employee System Functions SELECT ‘database’ = db_name(), ‘user’ = user_name(), login = suser_name()

6 1/18/00CSE 711 data mining6 Choosing Rows of SQL? Based on Comparisons SELECT fname, (salary * 1.1) FROM employee WHERE state = ‘NY’ Based on Ranges SELECT fname, (salary * 1.1) FROM employee WHERE birthdate BETWEEN ‘1/1/1950’ and ‘12/31/1970’ Based on Lists SELECT fname, salary FROM employee WHERE major IN (‘CS’, ‘CSE’, ‘ECE’, ‘IS’)

7 1/18/00CSE 711 data mining7 More on Choosing Rows of SQL? Based on Character Strings SELECT fname, lname FROM professor WHERE lname LIKE ‘%hari%’ Based on Unknown values SELECT fname FROM employee WHERE salary IS NULL Based on Several Search Arguments SELECT fname, salary FROM employee WHERE (major LIKE ‘CS%’, OR state =‘NY’) AND (salary > 25,000) Eliminating Duplicates SELECT DISTINCT city FROM authors Sorting SELECT fname, lname, salary FROM employee ORDER BY salary DESC

8 1/18/00CSE 711 data mining8 Generate Summary Values avg, count, max, min, sum, etc. (New “Group by” and “Having” clauses) SELECT title_id, copies_sold = SUM(qty) FROM sales GROUP BY title_id HAVING SUM(qty) > 30 Aggregate Functions of SQL?

9 1/18/00CSE 711 data mining9 Joining Tables (Inner Joins, Cross Joins, Outer Joins, Joins with More than Two Tables, Self Joins) Nesting SELECT Statements Subqueries Select Into UNION Operator etc. about SQL?


Download ppt "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."

Similar presentations


Ads by Google