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

Post on 24-May-2020

5 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

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

!

MySQL Workbench

!

MySQL Workbench

!

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 username@ischool.berkeley.edu >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 username@ischool.berkeley.edu:OUTPUT /some/local/directory

!Appendix !Tips for Recording output in Command Line

top related