sql playground
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1 KiB

-- in class examples
-- first, always see the data you are working with
SELECT * FROM employee
-- then, see the size of the data
SELECT COUNT(*) FROM employee
-- show winners of the nobel prize in 1950
SELECT yr, subject, winner FROM nobel
WHERE yr = 1950
-- show 1962 Literature prize winners
SELECT winner
FROM nobel
WHERE yr = 1950
AND subject = 'Literature'
-- find nobel prizes that Albert Einstein won
SELECT yr, subject
FROM nobel
WHERE winner = 'Albert Einstein'
-- Peace winners since 2000 inclusively
SELECT winner
FROM nobel
WHERE yr >= 2000
AND subject = 'Peace'
-- Good idea to show the criteria you are filtering on
SELECT winner, yr
FROM nobel
WHERE yr >= 2000
AND subject = 'Peace'
-- Show all details (year, subject winner) of winners from 1980 to 1989 of he Literature prize
SELECT *
FROM nobel
WHERE yr >= 1980
AND yr <= 1989
AND subject = 'Literature'
-- use something other than two ands - LIKE works
SELECT *
FROM nobel
WHERE yr LIKE '198%'
AND subject = 'Literature'
-- and we can also try this:
SELECT *
FROM nobel
WHERE yr BETWEEN 1980 AND 1989 -- this is inclusively specified
AND subject = 'Literature'