Entity / Attributes Entity represents a person / thing Entity represents an Access table Attributes describe facets of an entity Attributes represents.

Slides:



Advertisements
Similar presentations
SQL – Lesson II Grade 12.
Advertisements

Concepts of Database Management Seventh Edition
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts.
© Steven Alter, 2007, all rights reserved Database concepts Difference between a database and the Internet Reason for having a defined data structure Relational.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Query by example (based on notes by Silberchatz,Korth, and Sudarshan.
--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:  “%”
Structured Query Language Part I Chapter Three CIS 218.
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
Microsoft Access 2010 Chapter 7 Using SQL.
Computer Science 101 Web Access to Databases SQL – Extended Form.
SQL Operations Aggregate Functions Having Clause Database Access Layer A2 Teacher Up skilling LECTURE 5.
Chapter 4 Relational Databases and Enterprise Systems
Introduction to SQL J.-S. Chou Assistant Professor.
Slide 1 Chapter 2 Introduction to Structured Query Language (SQL) ‏
Concepts of Database Management, Fifth Edition
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
Chapter 3 Single-Table Queries
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
Database Management The single entity, the single table, plus some basic SQL.
Many-to-many (M:M) relationship M:M Concept: A Shipment can contain many types of Materials and a type of Material can be sent in many different shipments.
1. AFL-CIO What percentage of the funds received by Alabama K-12 public schools in school year was provided by the state of Alabama? a)44% b)53%
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
Relational Databases (MS Access)
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Concepts of Database Management Seventh Edition
Using Special Operators (LIKE and IN)
Structured Query Language. Group Functions What are group functions ? Group Functions Group functions operate on sets of rows to give one result per group.
One-to-many relationship Relational databases link several entities based on relationships that exist (based on modeling reality) 1:m relationship example:
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE)
Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?
Oracle DML Dr. Bernard Chen Ph.D. University of Central Arkansas.
Information Resource Engineering SQL4. Recap - Ordering Output  Usually, the order of rows returned in a query result is undefined.  The ORDER BY clause.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Computing & Information Sciences Kansas State University Monday, 17 Sep 2007CIS 560: Database System Concepts Lecture 12 of 42 Monday, 18 February 2008.
Source: Database System Concepts, Silberschatz etc Edited: Wei-Pang Yang, IM.NDHU, Introduction to Database CHAPTER 5 Other Relational Languages.
Structured Query Language Introduction. Basic Select SELECT lname, fname, phone FROM employees; Employees Table LNAMEFNAMEPHONE JonesMark SmithSara
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
SQL Aggregation Oracle and ANSI Standard SQL Lecture 9.
IFS180 Intro. to Data Management Chapter 11 - Subqueries.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
* Database is a group of related objects * Objects can be Tables, Forms, Queries or Reports * All data reside in Tables * A Row in a Table is a record.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
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 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.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Southern Methodist University CSE CSE 2337 Introduction to Data Management Chapter 2.
Computer Science & Engineering 2111 Inner Joins and Advanced Queries 1CSE 2111 Lecture-Advanced Queries.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Chapter 11 – Data Manipulation: Relational Algebra and SQL1 Unit 9: Data Manipulation: Relational Algebra and SQL IT238: Data Modeling and Database Design.
SQL Query Getting to the data ……..
Working with Tables: Join, Functions and Grouping
SQL FUNDAMENTALS CDSE Days 2018.
Access Quiz.
SQL – Entire Select.
Chapter 4 Summary Query.
Access: SQL Participation Project
Supplementary Data Tables, Utilization and Volume
CS122 Using Relational Databases and SQL
Section 4 - Sorting/Functions
‘ORDER BY’ Order by clause allows sorting of query results by one or more columns. Sorting can be done in ascending or descending. Default order is ascending.
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

Entity / Attributes Entity represents a person / thing Entity represents an Access table Attributes describe facets of an entity Attributes represents columns in an Access table 1 CLIENT *ClientID ClientName ClientServices ClientCity ClientState ClientRevenue

Identifiers / Primary Keys Every entity must be uniquely identified (via a primary key) Asterisk represents the primary key A primary key can be a single attribute or a combination of attributes Unique attributes can serve as the primary key (ClientName) A primary key can be created (ID) in situations where there are unique attributes 2 CLIENT *ClientID ClientName ClientServices ClientCity ClientState ClientRevenue

Example: Client Table 3 Client ClientID Client Name Client Services Client City Client State Client Revenue 1BK AssociatesCommercialPortlandOregon$210, BlalocIndustrialKansas CityMissouri$330, Bankton ElectricGovernmentNew York $210, BickIndustrialRaleighNorth Carolina$550, TX ElectricGovernmentHoustonTexas$160, CrowCommercialDallasTexas$270, GRBIndustrialAtlantaGeorgia$180, H&PIndustrialDenverColorado$90, LB&BIndustrialBostonMassachusetts$211, CongroIndustrialAtlantaGeorgia$122, Moss EnterprisesCommercialPhoenixArizona$33, RubyIndustrialSan AntonioTexas$344, Silver IndustriesIndustrialOmahaNebraska$218, TPHCommercialAnnaheimCalifornia$166,000.00

Querying: Client Table To show all of the data in the Client table. SELECT * FROM Client; 4 ClientID Client Name Client Services Client City Client State Client Revenue 1BK AssociatesCommercialPortlandOregon$210, BlalocIndustrialKansas CityMissouri$330, Bankton ElectricGovernmentNew York $210, BickIndustrialRaleighNorth Carolina$550, TX ElectricGovernmentHoustonTexas$160, CrowCommercialDallasTexas$270, GRBIndustrialAtlantaGeorgia$180, H&PIndustrialDenverColorado$90, LB&BIndustrialBostonMassachusetts$211, CongroIndustrialAtlantaGeorgia$122, Moss EnterprisesCommercialPhoenixArizona$33, RubyIndustrialSan AntonioTexas$344, Silver IndustriesIndustrialOmahaNebraska$218, TPHCommercialAnnaheimCalifornia$166,000.00

Selecting Specific Columns (vertical cut) 5 Client ClientID Client Name Client Services Client City Client State Client Revenue 1BK AssociatesCommercialPortlandOregon$210, BlalocIndustrialKansas CityMissouri$330, Bankton ElectricGovernmentNew York $210, BickIndustrialRaleighNorth Carolina$550, TX ElectricGovernmentHoustonTexas$160, CrowCommercialDallasTexas$270, GRBIndustrialAtlantaGeorgia$180, H&PIndustrialDenverColorado$90, LB&BIndustrialBostonMassachusetts$211, CongroIndustrialAtlantaGeorgia$122, Moss EnterprisesCommercialPhoenixArizona$33, RubyIndustrialSan AntonioTexas$344, Silver IndustriesIndustrialOmahaNebraska$218, TPHCommercialAnnaheimCalifornia$166,000.00

Selecting Specific Columns (vertical cut) Report a Client’s name, services, and revenues. Display order based on query (i.e. in order of the comma separators) SELECT ClientName, ClientServices, ClientRevenue FROM Client; 6 Client Name Client Services Client Revenue BK AssociatesCommercial$210, BlalocIndustrial$330, Bankton ElectricGovernment$210, BickIndustrial$550, TX ElectricGovernment$160, CrowCommercial$270, GRBIndustrial$180, H&PIndustrial$90, LB&BIndustrial$211, CongroIndustrial$122, Moss EnterprisesCommerical$33, RubyIndustrial$344, Silver IndustriesIndustrial$218, TPHCommercial$166,000.00

Selecting Specific Rows (horizontal cut) 7 Client ClientID Client Name Client Services Client City Client State Client Revenue 1BK AssociatesCommercialPortlandOregon$210, BlalocIndustrialKansas CityMissouri$330, Bankton ElectricGovernmentNew York $210, BickIndustrialRaleighNorth Carolina$550, TX ElectricGovernmentHoustonTexas$160, CrowCommercialDallasTexas$270, GRBIndustrialAtlantaGeorgia$180, H&PIndustrialDenverColorado$90, LB&BIndustrialBostonMassachusetts$211, CongroIndustrialAtlantaGeorgia$122, Moss EnterprisesCommercialPhoenixArizona$33, RubyIndustrialSan AntonioTexas$344, Silver IndustriesIndustrialOmahaNebraska$218, TPHCommercialAnnaheimCalifornia$166,000.00

Selecting Specific Rows (horizontal cut) Show all client data for client that contribute revenue less than $150,000. SELECT * FROM Client WHERE ClientRevenue < ; 8 ClientID Client Name Client Services Client City Client State Client Revenue 8H&PIndustrialDenverColorado$90, CongroIndustrialAtlantaGeorgia$122, Moss EnterprisesCommercialPhoenixArizona$33,000.00

Selecting Specific Data Within Columns & Rows 9 Client ClientID Client Name Client Services Client City Client State Client Revenue 1BK AssociatesCommercialPortlandOregon$210, BlalocIndustrialKansas CityMissouri$330, Bankton ElectricGovernmentNew York $210, BickIndustrialRaleighNorth Carolina$550, TX ElectricGovernmentHoustonTexas$160, CrowCommercialDallasTexas$270, GRBIndustrialAtlantaGeorgia$180, H&PIndustrialDenverColorado$90, LB&BIndustrialBostonMassachusetts$211, CongroIndustrialAtlantaGeorgia$122, Moss EnterprisesCommercialPhoenixArizona$33, RubyIndustrialSan AntonioTexas$344, Silver IndustriesIndustrialOmahaNebraska$218, TPHCommercialAnnaheimCalifornia$166,000.00

Selecting Specific Columns & Rows Display the Client’s name and revenues where revenue is greater than or equal to $270,000. SELECT ClientName, ClientRevenue from Client Where ClientRevenue >= ; 10 ClientNameClientRevenue Blaloc$330, Bick$550, Crow$270, Ruby$344,000.00

Selecting Specific Cases List client id, name and state who are based in either Texas or Arizona. SELECT clientID, clientName, clientState FROM Client where clientState = 'Texas' or ClientState = 'Arizona'; also SELECT clientID, clientName, clientState FROM Client where clientState in ('Texas', 'Arizona'); 11 clientIDclientNameclientState 5TX ElectricTexas 6CrowTexas 11Moss EnterprisesArizona 12RubyTexas

Excluding Specific Cases List client services and name for clients that provide services that are not Industrial. SELECT ClientServices, ClientName from Client where ClientServices <> 'Industrial'; also SELECT ClientServices, ClientName from Client where ClientServices Not In ('Industrial'); 12 ClientServicesClientName CommercialBK Associates GovernmentBankton Electric GovernmentTX Electric CommercialCrow CommercialMoss Enterprises CommercialTPH

Displaying Output in Order - Columns SELECT Clientname, ClientState from Client where ClientState = 'North Carolina'; SELECT ClientState, Clientname from Client where ClientState = 'North Carolina'; 13 Client NameClientState BickNorth Carolina ClientStateClientname North CarolinaBick

Displaying Output in Order - Rows Display ClientName, ClientCity, ClientRevenue firms where revenues are greater than $180,000 in order of descending revenue. Where revenues are equivalent, list the Client firms in alphabetical order (based on their city). SELECT ClientName, ClientCity, ClientRevenue FROM Client where ClientRevenue > order by ClientRevenue desc, ClientCity; 14 ClientNameClientCityClientRevenue BickRaleigh$550, RubySan Antonio$344, BlalocKansas City$330, CrowDallas$270, Silver IndustriesOmaha$218, LB&BBoston$211, Bankton ElectricNew York$210, BK AssociatesPortland$210,000.00

SQL Functions and Calculations COUNT, AVG, SUM, MIN, and MAX Find the average Client Revenue SELECT Avg(ClientRevenue) as AverageRevenue FROM Client; Display the Client name, state, and revenue (in thousands) for Client from Texas SELECT ClientName, ClientState, ClientRevenue/1000 as ThousandDollars FROM Client Where ClientState = 'Texas'; 15 AverageRevenue $221, ClientNameClientStateThousandDollars TX ElectricTexas160 CrowTexas270 RubyTexas344

Subqueries Subquery = A query within a query Report all Client names and revenue for those firms with revenues that exceed the average revenue for the group as a whole. SELECT ClientName, ClientRevenue From Client Where ClientRevenue > (SELECT AVG(ClientRevenue) From Client); 16 ClientNameClientRevenue Blaloc$330, Bick$550, Crow$270, Ruby$344,000.00

Like / Not Like List all Clients with a name starting with ‘B’. SELECT Clientname FROM Client Where ClientName Like 'B*'; List all Clients have do not have either an ‘S” or ‘B’ in their name SELECT Clientname FROM Client Where ClientName Not Like '*B*' and ClientName Not Like '*S*'; 17 Clientname BK Associates Blaloc Bankton Electric Bick Clientname TX Electric Crow H&P Congro TPH

DISTINCT Find the number of different states represented by the Client base SELECT Distinct ClientState as 'Client Locations' FROM Client; 18 'Client Locations' Arizona California Colorado Georgia Massachusetts Missouri Nebraska New York North Carolina Oregon Texas