SQL WORKSHOP September 9, 2014
!
1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server 3. Try a few SQL queries
!
!
AGENDA
!
Please download from - http://dev.mysql.com/downloads/workbench/ !
Depending on OS version, click on Download !
!!!
!
MySQL Workbench
!
Let’s try some queries
What is the length (in centimeters) of a Spotted Eagle Ray?
Customer No
ShipVia
Dest
Sites
BioSite
ShipVia
ShipWrck
BioLife DiveStok
DiveItem
DiveOrds
DiveCust
Customer No
ShipVia
Order No
Order No
Item No
Item No
Destination Name
Destination
Species No
Site No
Destination no
Site No
Destination no
Species No
Site No
!
!
SELECT BIOLIFE.Length_cm FROM BIOLIFE WHERE BIOLIFE.Common_Name=“Spotted Eagle Ray”
What is the length (in centimeters) of Spotted Eagle Ray?
Category
Species no
Common Name
Length (cm)
Species Name
Length (in)
Notes external
Graphic externalBioLife
!
Sample query
Which destination has the highest number of dive orders?
Customer No
ShipVia
Dest
Sites
BioSite
ShipVia
ShipWrck
BioLife DiveStok
DiveItem
DiveOrds
DiveCust
Customer No
ShipVia
Order No
Order No
Item No
Item No
Destination Name
Destination
Species No
Site No
Destination no
Site No
Destination no
Species No
Site No
!
!
SELECT DIVEORDS.Destination, COUNT(*) FROM DIVEORDS GROUP BY DIVEORDS.Destination *** Please note, COUNT, SUM, AVERAGE … etc are group by operations***
Which destination has the highest number of dive orders?
Customer No
Order no
Sale Date
Ship Via
DestinationCCExpDate
CCNumber
Payment MethodDiveOrds
No of People
Vacation Cost
Return Date
Depart Date
!
Sample query
In which site(s) might you find a Bat Ray?
Customer No
ShipVia
Dest
Sites
BioSite
ShipVia
ShipWrck
BioLife DiveStok
DiveItem
DiveOrds
DiveCust
Customer No
ShipVia
Order No
Order No
Item No
Item No
Destination Name
Destination
Species No
Site No
Destination no
Site No
Destination no
Species No
Site NoJoin 1
Join 2
!
SELECT SITES.Site_Name FROM BIOLIFE, BIOSITE, SITES WHERE BIOLIFE.Common_Name=“Bat Ray” AND BIOLIFE.Species_No=BIOSITE.Species_No AND BIOSITE.Site_No=SITES.Site_No
!
SQL query
In which site(s) might you find a Bat Ray?
Using a SSH client - Mac OS/Linux User: Terminal - Windows User: PuTTY !
>ssh [email protected] >mysql -p username
mysql>
!
!Appendix HOW TO:Connect MySQL Database from the Command Line
mysql> \T OUTPUT Logging to file ‘OUTPUT’ !-> select * from SITES; !mysql> \tOutfile disabled. mysql> \q Bye harbinger:~ --> more OUTPUT <OPEN ANOTHER TAB> :~$ scp [email protected]:OUTPUT /some/local/directory
!Appendix !Tips for Recording output in Command Line