SQL - 예제로 배우는 SQL 4

산하·2022년 5월 16일
0

SQL

목록 보기
5/9
post-thumbnail

문제 링크 바로가기 👀



👉🏻 SELECT from Nobel Tutorial


1. Winners from 1950

Q. Change the query shown so that it displays Nobel prizes for 1950.

A.

SELECT yr, subject, winner
  FROM nobel
 WHERE yr = 1950;

2. 1962 Literature

Q. Show who won the 1962 prize for literature.

A.

SELECT winner
  FROM nobel
 WHERE yr = 1962
   AND subject = 'literature'

3. Albert Einstein

Q. Show the year and subject that won 'Albert Einstein' his prize.

A.

SELECT yr, subject 
  FROM nobel
WHERE winner = 'Albert Einstein'

4.Recent Peace Prizes

Q. Give the name of the 'peace' winners since the year 2000, including 2000.

A.

SELECT winner 
  FROM nobel 
WHERE subject = 'peace' 
AND yr >= 2000

5. Literature in the 1980's

Q. Show all details (yr, subject, winner) of the literature prize winners for 1980 to 1989 inclusive.

A.

SELECT * FROM nobel
WHERE subject = 'literature'
AND yr >=1980 AND yr <= 1989

6. Only Presidents

Q. Show all details of the presidential winners:

  • Theodore Roosevelt
  • Woodrow Wilson
  • Jimmy Carter
  • Barack Obama

A.

SELECT * FROM nobel
  WHERE winner IN ('Theodore Roosevelt',
                  'Woodrow Wilson',
                  'Jimmy Carter',
                  'Barack Obama' )

7. John

Q. Show the winners with first name John

A.

SELECT winner FROM nobel 
  WHERE winner LIKE 'John%'

8. Chemistry and Physics from different years

Q. Show the year, subject, and name of physics winners for 1980 together with the chemistry winners for 1984.

A.

SELECT * FROM nobel
  WHERE subject = 'physics' AND yr = 1980
  OR subject = 'chemistry' AND yr = 1984

9. Exclude Chemists and Medics

Q. Show the year, subject, and name of winners for 1980 excluding chemistry and medicine

A.

SELECT * FROM nobel
WHERE subject != 'chemistry' AND subject != 'medicine'
AND yr = 1980

10. Early Medicine, Late Literature

Q. Show year, subject, and name of people who won a 'Medicine' prize in an early year (before 1910, not including 1910) together with winners of a 'Literature' prize in a later year (after 2004, including 2004)

A.

SELECT * FROM nobel
WHERE yr < 1910 
AND subject = 'Medicine'
OR yr >= 2004 
AND subject = 'Literature'

11. Umlaut

Q. Find all details of the prize won by PETER GRÜNBERG

A.

SELECT * FROM nobel
WHERE winner = 'PETER GRÜNBERG'

12. Apostrophe

Q. Find all details of the prize won by EUGENE O'NEILL

A.

SELECT * FROM nobel
WHERE winner = 'EUGENE O''NEILL'

13. Knights of the realm

Q. Knights in order

List the winners, year and subject where the winner starts with Sir. Show the the most recent first, then by name order.

A.

SELECT winner,yr,subject FROM nobel 
WHERE winner LIKE 'Sir%'
ORDER BY yr DESC, winner 

14. Chemistry and Physics last

Q. The expression subject IN ('chemistry','physics') can be used as a value

  • it will be 0 or 1.

Show the 1984 winners and subject ordered by subject and winner name; but list chemistry and physics last.

A.

SELECT winner, subject FROM nobel
WHERE yr = 1984
ORDER BY suject IN ('physics', 'Chmistry'), subject, winner
profile
반갑습니다 :) 백앤드 개발자 산하입니다!

0개의 댓글