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.

11-5-18.sql 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. -- in class examples
  2. -- first, always see the data you are working with
  3. SELECT * FROM employee
  4. -- then, see the size of the data
  5. SELECT COUNT(*) FROM employee
  6. -- show winners of the nobel prize in 1950
  7. SELECT yr, subject, winner FROM nobel
  8. WHERE yr = 1950
  9. -- show 1962 Literature prize winners
  10. SELECT winner
  11. FROM nobel
  12. WHERE yr = 1950
  13. AND subject = 'Literature'
  14. -- find nobel prizes that Albert Einstein won
  15. SELECT yr, subject
  16. FROM nobel
  17. WHERE winner = 'Albert Einstein'
  18. -- Peace winners since 2000 inclusively
  19. SELECT winner
  20. FROM nobel
  21. WHERE yr >= 2000
  22. AND subject = 'Peace'
  23. -- Good idea to show the criteria you are filtering on
  24. SELECT winner, yr
  25. FROM nobel
  26. WHERE yr >= 2000
  27. AND subject = 'Peace'
  28. -- Show all details (year, subject winner) of winners from 1980 to 1989 of he Literature prize
  29. SELECT *
  30. FROM nobel
  31. WHERE yr >= 1980
  32. AND yr <= 1989
  33. AND subject = 'Literature'
  34. -- use something other than two ands - LIKE works
  35. SELECT *
  36. FROM nobel
  37. WHERE yr LIKE '198%'
  38. AND subject = 'Literature'
  39. -- and we can also try this:
  40. SELECT *
  41. FROM nobel
  42. WHERE yr BETWEEN 1980 AND 1989 -- this is inclusively specified
  43. AND subject = 'Literature'