Hui Hu Ph.D.
Department of Epidemiology
College of Public Health and Health Professions & College of Medicine
January 27, 2020
Column
Row
Table
SELECT year, month, west
FROM tutorial.us_housing_units
SELECT *
FROM tutorial.us_housing_units
SELECT year, month, west
FROM tutorial.us_housing_units
LIMIT 100
SELECT year, month, west
FROM tutorial.us_housing_units
WHERE month=1
SELECT *
FROM tutorial.us_housing_units
WHERE west > 30
SELECT *
FROM tutorial.us_housing_units
WHERE month_name != 'January'
SELECT year, month, west, south, west+south AS west_plus+south
FROM tutorial.us_housing_units
In MySQL, LIKE is case insensitive, and there is no ILIKE
SELECT *
FROM tutorial.billboard_top_100_year_end
WHERE group LIKE 'Snoo%'
SELECT *
FROM tutorial.billboard_top_100_year_end
WHERE group ILIKE 'snoo%'
SELECT *
FROM tutorial.billboard_top_100_year_end
WHERE group ILIKE 'snoop_'
SELECT *
FROM tutorial.billboard_top_100_year_end
WHERE year_rank IN (1,2,3)
SELECT *
FROM tutorial.billboard_top_100_year_end
WHERE year_rank BETWEEN 5 AND 10
SELECT *
FROM tutorial.billboard_top_100_year_end
WHERE year_rank >= 5 AND year_rank <= 10
SELECT *
FROM tutorial.billboard_top_100_year_end
WHERE artist IS NULL
SELECT *
FROM tutorial.billboard_top_100_year_end
WHERE year = 2012 AND year_rank <=10
SELECT *
FROM tutorial.billboard_top_100_year_end
WHERE year_rank = 5 OR artist = 'Gotye'
SELECT *
FROM tutorial.billboard_top_100_year_end
WHERE year_rank NOT BETWEEN 5 AND 10
SELECT *
FROM tutorial.billboard_top_100_year_end
ORDER BY year_rank
SELECT *
FROM tutorial.billboard_top_100_year_end
ORDER BY year DESC, year_rank