Download presentation
Presentation is loading. Please wait.
Published byMoses Gibson Modified over 9 years ago
1
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
2
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
3
Example: Client Table 3 Client ClientID Client Name Client Services Client City Client State Client Revenue 1BK AssociatesCommercialPortlandOregon$210,000.00 2BlalocIndustrialKansas CityMissouri$330,000.00 3Bankton ElectricGovernmentNew York $210,000.00 4BickIndustrialRaleighNorth Carolina$550,000.00 5TX ElectricGovernmentHoustonTexas$160,000.00 6CrowCommercialDallasTexas$270,000.00 7GRBIndustrialAtlantaGeorgia$180,000.00 8H&PIndustrialDenverColorado$90,000.00 9LB&BIndustrialBostonMassachusetts$211,000.00 10CongroIndustrialAtlantaGeorgia$122,000.00 11Moss EnterprisesCommercialPhoenixArizona$33,000.00 12RubyIndustrialSan AntonioTexas$344,000.00 13Silver IndustriesIndustrialOmahaNebraska$218,000.00 14TPHCommercialAnnaheimCalifornia$166,000.00
4
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,000.00 2BlalocIndustrialKansas CityMissouri$330,000.00 3Bankton ElectricGovernmentNew York $210,000.00 4BickIndustrialRaleighNorth Carolina$550,000.00 5TX ElectricGovernmentHoustonTexas$160,000.00 6CrowCommercialDallasTexas$270,000.00 7GRBIndustrialAtlantaGeorgia$180,000.00 8H&PIndustrialDenverColorado$90,000.00 9LB&BIndustrialBostonMassachusetts$211,000.00 10CongroIndustrialAtlantaGeorgia$122,000.00 11Moss EnterprisesCommercialPhoenixArizona$33,000.00 12RubyIndustrialSan AntonioTexas$344,000.00 13Silver IndustriesIndustrialOmahaNebraska$218,000.00 14TPHCommercialAnnaheimCalifornia$166,000.00
5
Selecting Specific Columns (vertical cut) 5 Client ClientID Client Name Client Services Client City Client State Client Revenue 1BK AssociatesCommercialPortlandOregon$210,000.00 2BlalocIndustrialKansas CityMissouri$330,000.00 3Bankton ElectricGovernmentNew York $210,000.00 4BickIndustrialRaleighNorth Carolina$550,000.00 5TX ElectricGovernmentHoustonTexas$160,000.00 6CrowCommercialDallasTexas$270,000.00 7GRBIndustrialAtlantaGeorgia$180,000.00 8H&PIndustrialDenverColorado$90,000.00 9LB&BIndustrialBostonMassachusetts$211,000.00 10CongroIndustrialAtlantaGeorgia$122,000.00 11Moss EnterprisesCommercialPhoenixArizona$33,000.00 12RubyIndustrialSan AntonioTexas$344,000.00 13Silver IndustriesIndustrialOmahaNebraska$218,000.00 14TPHCommercialAnnaheimCalifornia$166,000.00
6
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,000.00 BlalocIndustrial$330,000.00 Bankton ElectricGovernment$210,000.00 BickIndustrial$550,000.00 TX ElectricGovernment$160,000.00 CrowCommercial$270,000.00 GRBIndustrial$180,000.00 H&PIndustrial$90,000.00 LB&BIndustrial$211,000.00 CongroIndustrial$122,000.00 Moss EnterprisesCommerical$33,000.00 RubyIndustrial$344,000.00 Silver IndustriesIndustrial$218,000.00 TPHCommercial$166,000.00
7
Selecting Specific Rows (horizontal cut) 7 Client ClientID Client Name Client Services Client City Client State Client Revenue 1BK AssociatesCommercialPortlandOregon$210,000.00 2BlalocIndustrialKansas CityMissouri$330,000.00 3Bankton ElectricGovernmentNew York $210,000.00 4BickIndustrialRaleighNorth Carolina$550,000.00 5TX ElectricGovernmentHoustonTexas$160,000.00 6CrowCommercialDallasTexas$270,000.00 7GRBIndustrialAtlantaGeorgia$180,000.00 8H&PIndustrialDenverColorado$90,000.00 9LB&BIndustrialBostonMassachusetts$211,000.00 10CongroIndustrialAtlantaGeorgia$122,000.00 11Moss EnterprisesCommercialPhoenixArizona$33,000.00 12RubyIndustrialSan AntonioTexas$344,000.00 13Silver IndustriesIndustrialOmahaNebraska$218,000.00 14TPHCommercialAnnaheimCalifornia$166,000.00
8
Selecting Specific Rows (horizontal cut) Show all client data for client that contribute revenue less than $150,000. SELECT * FROM Client WHERE ClientRevenue < 150000; 8 ClientID Client Name Client Services Client City Client State Client Revenue 8H&PIndustrialDenverColorado$90,000.00 10CongroIndustrialAtlantaGeorgia$122,000.00 11Moss EnterprisesCommercialPhoenixArizona$33,000.00
9
Selecting Specific Data Within Columns & Rows 9 Client ClientID Client Name Client Services Client City Client State Client Revenue 1BK AssociatesCommercialPortlandOregon$210,000.00 2BlalocIndustrialKansas CityMissouri$330,000.00 3Bankton ElectricGovernmentNew York $210,000.00 4BickIndustrialRaleighNorth Carolina$550,000.00 5TX ElectricGovernmentHoustonTexas$160,000.00 6CrowCommercialDallasTexas$270,000.00 7GRBIndustrialAtlantaGeorgia$180,000.00 8H&PIndustrialDenverColorado$90,000.00 9LB&BIndustrialBostonMassachusetts$211,000.00 10CongroIndustrialAtlantaGeorgia$122,000.00 11Moss EnterprisesCommercialPhoenixArizona$33,000.00 12RubyIndustrialSan AntonioTexas$344,000.00 13Silver IndustriesIndustrialOmahaNebraska$218,000.00 14TPHCommercialAnnaheimCalifornia$166,000.00
10
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 >= 270000; 10 ClientNameClientRevenue Blaloc$330,000.00 Bick$550,000.00 Crow$270,000.00 Ruby$344,000.00
11
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
12
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
13
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
14
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 > 180000 order by ClientRevenue desc, ClientCity; 14 ClientNameClientCityClientRevenue BickRaleigh$550,000.00 RubySan Antonio$344,000.00 BlalocKansas City$330,000.00 CrowDallas$270,000.00 Silver IndustriesOmaha$218,000.00 LB&BBoston$211,000.00 Bankton ElectricNew York$210,000.00 BK AssociatesPortland$210,000.00
15
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,000.00 ClientNameClientStateThousandDollars TX ElectricTexas160 CrowTexas270 RubyTexas344
16
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,000.00 Bick$550,000.00 Crow$270,000.00 Ruby$344,000.00
17
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
18
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.