Exercise:)FilteringDatawithSQL)Statements) · Exercise:)FilteringDatawithSQL)Statements)!...

8
Exercise: Filtering Data with SQL Statements The data displayed in table and map view can be filtered so that only a subset of the data is displayed. This is accomplished through the execution of SQL statements that run against the table. To view the SQL editor select the SQL button from the table view interface. You can then write custom SQL commands to filter the data. In this exercise you will filter data in a table to restrict the records displayed in the table and map views. Step 1: Login to CartoDB

Transcript of Exercise:)FilteringDatawithSQL)Statements) · Exercise:)FilteringDatawithSQL)Statements)!...

Page 1: Exercise:)FilteringDatawithSQL)Statements) · Exercise:)FilteringDatawithSQL)Statements)! The$datadisplayedintable$andmapview$canbe$filteredsothat$only$a subset$of$thedataisdisplayed.$Thisisaccomplished$through

Exercise:  Filtering  Data  with  SQL  Statements    The  data  displayed  in  table  and  map  view  can  be  filtered  so  that  only  a  subset  of  the  data  is  displayed.  This  is  accomplished  through  the  execution  of  SQL  statements  that  run  against  the  table.  To  view  the  SQL  editor  select  the  SQL  button  from  the  table  view  interface.  You  can  then  write  custom  SQL  commands  to  filter  the  data.

In  this  exercise  you  will  filter  data  in  a  table  to  restrict  the  records  displayed  in  the  table  and  map  views.

 Step  1:  Login  to  CartoDB    

Page 2: Exercise:)FilteringDatawithSQL)Statements) · Exercise:)FilteringDatawithSQL)Statements)! The$datadisplayedintable$andmapview$canbe$filteredsothat$only$a subset$of$thedataisdisplayed.$Thisisaccomplished$through

• Go  to  http://cartodb.com  and  login  to  your  account.  

   

Step 2: Import a Dataset In  this  step  you  will  import  a  dataset  provided  by  CartoDB.

Page 3: Exercise:)FilteringDatawithSQL)Statements) · Exercise:)FilteringDatawithSQL)Statements)! The$datadisplayedintable$andmapview$canbe$filteredsothat$only$a subset$of$thedataisdisplayed.$Thisisaccomplished$through

• From  the  Dashboard • From  the  CartoDB  dashboard  select  the  Maps  dropdown  and  then  

Your  datasets.  

• Click  Data  Library  

Page 4: Exercise:)FilteringDatawithSQL)Statements) · Exercise:)FilteringDatawithSQL)Statements)! The$datadisplayedintable$andmapview$canbe$filteredsothat$only$a subset$of$thedataisdisplayed.$Thisisaccomplished$through

 

• Click  the  Search  icon  and  then  type  “Populated  places”.    Click  the  enter  key  on  your  keyboard.  

Page 5: Exercise:)FilteringDatawithSQL)Statements) · Exercise:)FilteringDatawithSQL)Statements)! The$datadisplayedintable$andmapview$canbe$filteredsothat$only$a subset$of$thedataisdisplayed.$Thisisaccomplished$through

 

• One  dataset  should  be  returned.    Click  the  name  of  the  dataset  and  then  ‘Connect  dataset’.  

 

• After  the  dataset  has  been  imported  switch  to  Map  View.    In  the  next  step  we’ll  use  a  SQL  statement  to  filter  this  dataset  so  that  the  returned  results  are  limited.  

Page 6: Exercise:)FilteringDatawithSQL)Statements) · Exercise:)FilteringDatawithSQL)Statements)! The$datadisplayedintable$andmapview$canbe$filteredsothat$only$a subset$of$thedataisdisplayed.$Thisisaccomplished$through

 

Step  3:  Filter  the  Data  

• Switch  back  to  Data  View  and  find  the  ‘pop_max’  column.      We’re  going  to  define  a  filter  that  will  display  only  the  populated  places  where  the  population  is  greater  than  10  million.  

• Click  the  SQL  button  seen  below.  

Page 7: Exercise:)FilteringDatawithSQL)Statements) · Exercise:)FilteringDatawithSQL)Statements)! The$datadisplayedintable$andmapview$canbe$filteredsothat$only$a subset$of$thedataisdisplayed.$Thisisaccomplished$through

 

• Define  the  query  as  follows  and  click  the  ‘Apply  query’  button.  

Page 8: Exercise:)FilteringDatawithSQL)Statements) · Exercise:)FilteringDatawithSQL)Statements)! The$datadisplayedintable$andmapview$canbe$filteredsothat$only$a subset$of$thedataisdisplayed.$Thisisaccomplished$through

 

• Switch  back  to  Map  View  to  see  the  results.  

   

• Double  click  the  cell  in  the  first  row  of  the  table  under  the  ‘city’  column.