1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- -- 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'
|