Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 5: Functions.

Slides:



Advertisements
Similar presentations
Relational Database Systems Higher Information Systems Advanced Implementation in MySQL/PHP.
Advertisements

Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 3: Joins Part I.
N.G.Acharya & D.K.Marathe college Chembur-E, Mumbai-71
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 7: Subqueries and Set Operations.
Northwind2003 database 11 Aug Sakila database 11 Aug
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Chapter 6 Set Functions.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 7: Aggregates.
Introduction to Structured Query Language (SQL)
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 7: Subqueries and Set Operations.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lab 2: Single-Table Selections.
Introduction to Structured Query Language (SQL)
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 10: Database Design and.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 1: Introduction to Relational.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 6: Set Functions.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 3: Joins Part I.
Using Relational Databases and SQL
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Manipulation Language.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 6: Midterm Review.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 5: Functions.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Laboratory 1: Introduction to Relational.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 7: Aggregates.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 5: Subqueries and Set Operations.
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 4: Joins Part II.
Introduction to Structured Query Language (SQL)
Using Relational Databases and SQL Department of Computer Science California State University, Los Angeles Lecture 7:
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 4: Joins Part II.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 10: Data Definition Language.
Introduction to SQL Structured Query Language Martin Egerhill.
Using Relational Databases and SQL Department of Computer Science California State University, Los Angeles Lecture 8: Subqueries.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Using Relational Databases and SQL Department of Computer Science California State University, Los Angeles Lecture 5: Functions.
U:/msu/course/cse/103 Day 10, Slide 1 CSE 103 Students: Your BTs have been graded. See Erica or Jo with questions or stay.
10 May Microsoft Access 2010 Relational databases’ program Part of the Microsoft Office package Administer relational database Update database through.
Using Relational Databases and SQL John Hurley Department of Computer Science California State University, Los Angeles Lecture 3: Joins Part I.
Using Relational Databases and SQL Department of Computer Science California State University, Los Angeles Lecture 6: Midterm Review.
Upgrading to SQL Server 2000 Kashef Mughal. Multiple Versions SQL Server 2000 supports multiple versions of SQL Server on the same machine It does that.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Using Relational Databases and SQL John Hurley Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
Chapter 11 Functions and Groups Part C. SQL Copyright 2005 Radian Publishing Co.
Using Relational Databases and SQL Department of Computer Science California State University, Los Angeles Lecture 4: Joins Part II.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 ITN270 Advanced Internet Databases Lecture 02. Operators and Function Reference Topics: – Explain & Demonstrate How You Can Use MySQL Operators – Overview.
Advanced SELECT Queries CS 146. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data Note the default formats… SELECT.
Lecture 8 – SQL Joins – assemble new views from existing tables INNER JOIN’s The Cartesian Product Theta Joins and Equi-joins Self Joins Natural Join.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
String and General Procedures. Answer to the last question of Exam 1 Start Get a number Divide the Number By 2 Is the quotient Equal to 1? Print The Remain.
1 Session 6: Database Best Practice iNET Academy Open Source Web Development.
Building java programs, chapter 3 Parameters, Methods and Objects.
Component 4: Introduction to Information and Computer Science Unit 6: Databases and SQL Lecture 6 This material was developed by Oregon Health & Science.
# 1# 1 QueriesQueries How do we ask questions of the data? What is SELECT? What is FROM? What is WHERE? What is a calculated field? Spring 2010 CS105.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Using Structures With CFCs By Selene Bainum. June 27 th - 30 th 2007www.cfunited.com Why Am I here? Familiar with structures Familiar with ColdFusion.
CS122 Using Relational Databases and SQL Huiping Guo Department of Computer Science California State University, Los Angeles 2. Single Table Queries.
CS 122: Lecture 3 Joins (Part 1) Tarik Booker CS 122 California State University, Los Angeles October 7, 2014.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
1 Section 3 - Select Statement u The Select statement allows you to... –Display Data –Specify Selection Criteria –Sort Data –Group Data for reporting –Use.
Tarik Booker California State University, Los Angeles October 21, 2014
Chapter 9 SQL and RDBMS Part C. SQL
This shows the user interface and the SQL Select for a situation with two criteria in an AND relationship.
Built-in Functions. Usage of Wildcards
CS122 Using Relational Databases and SQL
Chapter 11 Functions and Groups
CS122 Using Relational Databases and SQL
CS313T Advanced Programming language
Presentation transcript:

Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 5: Functions

Miscellany Lab and Homework #3 Questions? Go over some problems? Left and Right Join Comments Which attribute do you check for NULL? Should use the primary key attribute When to Use DISTINCT One-to-many and many-to-many relationships

Topics for Today Functions String Functions (Pages 117 – 120)‏ Date and Time Functions (Pages 120 – 123)‏ Control Flow Functions (Page 125)‏ Comparison Functions (Pages 125 – 126)‏ Numeric Functions (Not in book)‏

What is a Function? Portion of prewritten code in MySQL used to perform a very specific task Syntax: function_name(argument_list)‏ argument_list = [arg1, arg2, arg3,...] Examples: SELECT LENGTH('STEVEN'); -- output is 6 SELECT SIN( ); -- output is 2.6e-6 SELECT CURDATE(); -- output is

Function Tips Don't Try to Memorize Everything Too many functions Every DBMS vendor uses different functions Look them up in the book, on the internet, etc. Get Parentheses Right Type in parentheses first, then fill in the arguments Nested Functions Type each function in separately in notepad When done, substitutes nested functions back in

String Functions CHAR_LENGTH(str)‏ CONCAT(str1, str2,...)‏ CONCAT_WS(separator, str1, str2,...)‏ FORMAT(number, decimal_places)‏ LEFT(str, len), RIGHT(str, len)‏ LOCATE(substr, str), LOCATE(substr, str, pos)‏ LOWER(str), UPPER(str)‏

More String Functions SUBSTRING(str, pos, len)‏ SUBSTRING_INDEX(str, delim, count)‏ TRIM(str), LTRIM(str), RTRIM(str)‏ More string functions can be found here.here.

Date and Time Functions CURDATE()‏ DATEDIFF(date1, date2)‏ DATE_ADD(date, n_days)‏ DATE_ADD(date, INTERVAL value type)‏ DATE_FORMAT(date, format_str)‏ DATE_SUB(date, n_days)‏ DATE_SUB(date, INTERVAL value type)‏

More Date and Time Functions DAYOFMONTH(date), DAY(date)‏ DAYOFWEEK(date)‏ DAYOFYEAR(date)‏ LAST_DAY(date)‏ MONTH(date)‏ NOW()‏ TO_DAYS(date)‏ More date and time functions can be found here.here

Control Flow Functions IF(condition, true_expr, false_expr)‏ IFNULL(expr1, expr2)‏ CASE WHEN expr1 IS NULL THEN expr2 ELSE expr1 END NULLIF(expr1, expr2)‏ CASE WHEN expr1 == expr2 THEN NULL ELSE expr1 END More information on control functions can be found here.here

Cast Functions CAST(expr AS type)‏ CONVERT(expr, type)‏ More information on cast functions can be found here. here

Numerical Functions ABS(value)‏ CEIL(value), CEILING(value)‏ COS(value), SIN(value), TAN(value)‏ DEGREES(value), RADIANS(value), PI()‏ FLOOR(value)‏ POW(X, Y), SQRT(X)‏ ROUND(value), ROUND(value, decimal_places)‏ TRUNCATE(value, decimal_places)‏

Numerical Functions More numerical functions can be found here.here

Sample Questions Report the artist name and member name for each member who is the responsible party for each artist. Concatenate the first and last name of each member with a space between. Modify the previous exercise to also report the home phone number, formatted as (xxx)xxx- xxxx. Report the studio name and the first name of each studio contact. Report the studio name and the last name of each studio contact.

More Sample Questions Report the artist name and the age in years of the responsible member for each artist at the time of that artist's entry date. Report all genres from the Genre table, capitalizing the first letter of each.