Mdst 3559-02-24-sql2

302 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
302
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mdst 3559-02-24-sql2

  1. 1. SQL 2<br />MDST 3559: DataestheticsProf. Alvarado02/24/2011<br />
  2. 2. Business<br />PHP lessons today and tomorrow <br />2 today, 4 tomorrow – can on move?<br />To meet in room 323<br />
  3. 3. Review<br />Data structures<br />Have addressable elements<br />Have Categories, Instances, and Values<br />Data models<br />Categories are implicitly related to each other<br />Organized around an implicit subject<br />Each instance (e.g. a row in table) is an example of the subject<br />
  4. 4. What is the implied subject of a phone book?<br />
  5. 5. Example<br />What is the implicit subject?<br />CATEGORIES<br />EACH ROW IS AN INSTANCE, EACH CELL CONTAINS VALUES<br />
  6. 6. IMPLIED SUBJECT<br />COUNTRY<br />(owns)<br />(uses)<br />SOCIAL NETWORK<br />US Debt<br />Country X uses social network Y<br />Country X owns US Debt Z (in billions of $)<br />
  7. 7. Overview<br />When last we met <br />We created a MySQL account on UVA’s server<br />We created a database for our account<br />We logged into phpMyAdmin to see our new database<br />Today we will learn how to <br />Upload CSV data to MySQL<br />Search and query this data<br />Create new tables of data from scratch<br />Learn some basic SQL commands to interact with the data<br />
  8. 8. Exercise<br />Go to database on phpMyAdmin<br />https://dbm2.itc.virginia.edu/phpmyadmin<br />Download the two CSV files<br />Import into your database<br />Explore<br />See:<br />http://pages.shanti.virginia.edu/Dataesthetics_S11/archives/187<br />
  9. 9. Exercise: Modify Table<br />Familiarize yourself with the interface<br />Left and Right sides<br />On the Right: Top and Bottom<br />Go to Operations view to change table name<br />Go to Structure view to modify columns<br />Click on icon next to table name<br />Or click on Structure tab when looking at table<br />Review data types<br />
  10. 10. Data Types<br />See http://pages.shanti.virginia.edu/Dataesthetics_S11/?p=194&preview=true<br />
  11. 11. Exercise: Searches<br />Use the Search function to:<br />Find all countries that use Facebook<br />Find China in both tables<br />Find countries that own a debt larger than 50<br />
  12. 12. Exercise: Queries<br />Use the SQL function to make calls with the following SQL keywords<br />SELECT<br />FROM<br />WHERE<br />ORDER BY<br />DISTINCT<br />Syntax<br />Table names and columns can be quoted with “back ticks”<br />Strings quotes with single quotes<br />
  13. 13. Exercise: Joins<br />SELECT *<br />FROM table1, table2 <br />WHERE table1.country = table2.country<br />
  14. 14. Exercise: Joins<br />SELECT table1.country, table1.debt, table2.network<br />FROM table1, table2 <br />WHERE table1.country = table2.country<br />
  15. 15. Exercise: LEFT Joins<br />SELECT table1.country, table1.debt, table2.network<br />FROM table1<br />LEFT JOIN table2 <br />ON table1.country = table2.country<br />
  16. 16. Dirty Data<br />Why does the join fail?<br />Clean up the data to make it work<br />Try again<br />
  17. 17. Exercise: Views<br />Save your SQL as a View using “CREATE VIEW” link at bottom of report<br />
  18. 18. Exercise: Create a table<br />

×