More SQL Statements.

Slides:



Advertisements
Similar presentations
Paul Mundy Microsoft Excel Tips and tricks.
Advertisements

SQL Structured Query Language. SQL The SELECT Statement The SELECT statement is used to select data from a table. The tabular result is stored in a result.
From: SQL From:
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Databases Tutorial 2 Further Select Statements. Objectives for Week Data types Sort retrieved data Formatting output.
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems.
CITY UNIVERSITY / Vysoká Škola Manažmentu.:IS Information Systems :. © Martina Cesalova, 2005 MS ACCESS 1 Start Microsoft Access – New - Blank Database.
Lecture8:Data Manipulation in SQL Advanced SQL queries Ref. Chapter5 Lecture8 1.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
ZEIT2301 Design of Information Systems SQL: Computing Statistics School of Engineering and Information Technology Dr Kathryn Merrick.
SQL Oracle PL/SQL. Select SELECT column1, column2,...columnN FROM table_name WHERE condition; SELECT column1, column2,...columnN FROM table_name WHERE.
Exam #2 Review with Answers.  The entire exam will be on the computer  You can use search engines, Oracle SQL help, notes, books, and PPT’s  You can.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
LOGO 1 Lab_04: Basic SQL. 2 Outline  The ORDER BY Keyword  SQL ORDER BY Syntax  SQL NULL Values.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Fox MIS Spring 2011 Database Week 5 SQL basics SELECT, INSERT, UPDATE, DELETE.
Comp12 cont…. Using Quotes Note that we have used single quotes around the conditional values in the examples. SQL uses single quotes around text values.
Lab_03: Basic SQL.
Advanced SELECT Queries CS 146. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data Note the default formats… SELECT.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
INSERT Statement. 2 home back first prev next last What Will I Learn? Give examples of why it is important to be able to alter the data in a database.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
SQL SELECT Getting Data from the Database. Basic Format SELECT, FROM WHERE (=, >, LIKE, IN) ORDER BY ; SELECT LastName, FirstName, Phone, City FROM Customer.
Chapter 11 Database and SQL. Flat Files and Databases Flat files Databases Advantages Efficient use of resources Access control Disadvantages Security.
IS6146 Databases for Management Information Systems Lecture 4: SQL IV – SQL Functions and Procedures Rob Gleasure robgleasure.com.
1 БАЗЫ ДАННЫХ. 2 ПРЕДЛОЖЕНИЯ SQL ВЫБОРКА - SELECT SELECT [предикат] { * | таблица.* | [таблица.]поле_1 [AS псевдоним_1] [, [таблица.]поле_2 [AS псевдоним_2]
IST 210 More SQL Todd Bacastow IST 210: Organization of Data.
College of Information Technology, Universiti Tenaga Nasional1 Lab 2: Single-row Functions CISB224 01A CCSB244 01A Semester I, 2008/2009.
به نام خدا SQL QUIZ جوانمرد Website: ejavanmard.blogfa.com.
Displaying Data with XSLT ©NIITeXtensible Markup Language/Lesson 6/Slide 1 of 45 Objectives In this lesson, you will learn to: * Perform conditional formatting.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
SQL Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database.
1 ORACLE I 3 – SQL 1 Salim Phone: YM: talim_bansal.
Chapter 10 - EQUALITY AND INEQUALITY PREDICATES MeaningPredicate Equal to= Not equal to Less than< Less than or equal to Greater than.
2b. Create an Access Database Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis with Spreadsheets 1.
Fundamental of Database Systems
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Order Database – ER Diagram
How to: SQL By: Sam Loch.
From: SQL From:
Prepared By: Bobby Wan Microsoft Access Prepared By: Bobby Wan
Rob Gleasure robgleasure.com
MySQL DML Commands By Prof. B.A.Khivsara
In this session, you will learn to:
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Order Database – ER Diagram
IST 210: Organization of Data
Has Payment, for AMI, to above National Average Hospitals, Increased?
COMP519: Web Programming Autumn 2015
MIS2502: Data Analytics Converting ERDs to Schemas
Rob Gleasure robgleasure.com
SQL – Entire Select.
Lesson Plan Instructional Objective Learning Objective
M1G Introduction to Database Development
Structured Query Language
ER Diagram Master How to use this template
Chapter 4 Introduction to MySQL.
PHP and MySQL.
Lecture 5 SQL FUNCTIONS.
Lab 3: Single-row Functions
MIS2502: Data Analytics Relational Data Modeling 3
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
Concept of grouping SELECT statement have:
Presentation transcript:

More SQL Statements

Orders Table O_Id OrderDate OrderPrice Customer 1 2008/11/12 1000 Hansen 2 2008/10/23 1600 Nilsen 3 2008/09/02 700 4 2008/09/03 300 5 2008/08/30 2000 Jensen 6 2008/10/04 100

Now we want to find the average value of the "OrderPrice" fields. SELECT AVG(OrderPrice) AS OrderAverage FROM Orders OrderAverage 950

Now we want to find the customers that have an OrderPrice value higher than the average OrderPrice value. SELECT Customer FROM Orders WHERE OrderPrice>(SELECT AVG(OrderPrice) FROM Orders) Customer Hansen Nilsen Jensen

Now we want to count the number of orders from "Customer Nilsen". SELECT COUNT(Customer) AS CustomerNilsen FROM Orders WHERE Customer='Nilsen' CustomerNilsen 2

SELECT COUNT(*) AS NumberOfOrders FROM Orders 6

SELECT COUNT(DISTINCT Customer) AS NumberOfCustomers FROM Orders Now we want to count the number of unique customers in the "Orders" table. SELECT COUNT(DISTINCT Customer) AS NumberOfCustomers FROM Orders NumberOfCustomers 3

Now we want to find the largest value of the "OrderPrice" column. SELECT MAX(OrderPrice) AS LargestOrderPrice FROM Orders LargestOrderPrice 2000

Now we want to find the smallest value of the "OrderPrice" column. SELECT MIN(OrderPrice) AS SmallestOrderPrice FROM Orders SmallestOrderPrice 100

Now we want to find the sum of all "OrderPrice" fields". SELECT SUM(OrderPrice) AS OrderTotal FROM Orders OrderTotal 5700

Now we want to find if any of the customers have a total order of less than 2000. SELECT Customer,SUM(OrderPrice) FROM Orders GROUP BY Customer HAVING SUM(OrderPrice)<2000 Customer SUM(OrderPrice) Nilsen 1700

Now we want to find if the customers "Hansen" or "Jensen" have a total order of more than 1500. SELECT Customer,SUM(OrderPrice) FROM Orders WHERE Customer='Hansen' OR Customer='Jensen' GROUP BY Customer HAVING SUM(OrderPrice)>1500 Customer SUM(OrderPrice) Hansen 2000 Jensen

Persons Table P_Id LastName FirstName Address City 1 Hansen Ola Timoteivn 10 Sandnes 2 Svendson Tove Borgvn 23 3 Pettersen Kari Storgt 20 Stavanger

SELECT UCASE(LastName) as LastName,FirstName FROM Persons Now we want to select the content of the "LastName" and "FirstName" columns above, and convert the "LastName" column to uppercase. SELECT UCASE(LastName) as LastName,FirstName FROM Persons LastName FirstName HANSEN Ola SVENDSON Tove PETTERSEN Kari

SELECT LCASE(LastName) as LastName,FirstName FROM Persons Now we want to select the content of the "LastName" and "FirstName" columns above, and convert the "LastName" column to lowercase. SELECT LCASE(LastName) as LastName,FirstName FROM Persons LastName FirstName hansen Ola svendson Tove pettersen Kari

SELECT MID(City,1,4) as SmallCity FROM Persons Now we want to extract the first four characters of the "City" column above. SELECT MID(City,1,4) as SmallCity FROM Persons SmallCity Sand Stav

SELECT LEN(Address) as LengthOfAddress FROM Persons Now we want to select the length of the values in the "Address" column above. SELECT LEN(Address) as LengthOfAddress FROM Persons LengthOfAddress 12 9

Products Table Prod_Id ProductName Unit UnitPrice 1 Jarlsberg 1000 g 10.45 2 Mascarpone 32.56 3 Gorgonzola 15.67

SELECT ProductName, ROUND(UnitPrice,0) as UnitPrice FROM Products Now we want to display the product name and the price rounded to the nearest integer. SELECT ProductName, ROUND(UnitPrice,0) as UnitPrice FROM Products ProductName UnitPrice Jarlsberg 10 Mascarpone 33 Gorgonzola 16

Now we want to display the products and prices per today's date. SELECT ProductName, UnitPrice, Now() as PerDate FROM Products ProductName UnitPrice PerDate Jarlsberg 10.45 10/7/2008 11:25:02 AM Mascarpone 32.56 Gorgonzola 15.67

Now we want to display the products and prices per today's date (with today's date displayed in the following format "YYYY-MM-DD"). SELECT ProductName, UnitPrice, FORMAT(Now(),'YYYY-MM-DD') as PerDate FROM Products ProductName UnitPrice PerDate Jarlsberg 10.45 2008-10-07 Mascarpone 32.56 Gorgonzola 15.67