Top Banner
SQL WORKSHOP September 9, 2014
14

SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

May 24, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

SQL WORKSHOP

September 9, 2014

Page 2: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

!

1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server 3. Try a few SQL queries

!

!

AGENDA

Page 3: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

!

Please download from - http://dev.mysql.com/downloads/workbench/ !

Depending on OS version, click on Download !

!!!

!

MySQL Workbench

Page 4: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

!

MySQL Workbench

Page 5: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

!

MySQL Workbench

Page 6: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

!

MySQL Workbench

Page 7: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

!

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

Page 8: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

!

!

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

Page 9: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

!

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

Page 10: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

!

!

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

Page 11: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

!

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

Page 12: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

!

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?

Page 13: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

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

Page 14: SQL WORKSHOP - UC Berkeley School of Informationcourses.ischool.berkeley.edu/i257/f14/Workshop_1.pdf · 1. Install MySQL workbench 2. Setup connection and access iSchool MySQL server

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