융무의 기술블로그
article thumbnail
Published 2020. 7. 2. 20:29
[SQL][sqlzoo] SELECT from Nobel Algorithm/SQL

SELECT from Nobel                                                                                                                      

 

SELECT from Nobel Tutorial - SQLZOO

nobel yr subject winner 1960 Chemistry Willard F. Libby 1960 Literature Saint-John Perse 1960 Medicine Sir Frank Macfarlane Burnet 1960 Medicine Peter Madawar ... nobel Nobel Laureates We continue practicing simple SQL queries on a single table. This tutor

sqlzoo.net

1.Winners from 1950

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

2.1962 Literature

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

3.Albert Einstein

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

4.Recent Peace Prizes

select winner 
from nobel 
where subject='peace' and yr>=2000

5.Literature in the 1980's

select yr,subject,winner 
from nobel 
where subject='Literature' and yr between 1980 and 1989

6.Only Presidents

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

7.John

select winner 
from nobel 
where winner like'john%'

8.Chemistry and Physics from different years

select yr,subject,winner 
from nobel 
where (subject='Physics'and yr='1980') or (subject='Chemistry' and yr='1984')

9.Exclude Chemists and Medics

select * 
from nobel 
where yr='1980' and subject not in ('Chemistry', 'Medicine')

10.Early Medicine, Late Literature

select * 
from nobel 
where ( subject='Medicine' and yr<'1910') or ( subject='Literature' and yr>='2004')

11.Umlaut

select * 
from nobel 
where winner='PETER GRÜNBERG'

12.Apostrophe

select * 
from nobel 
where winner like'EUGENE O%'

13.Knights of the realm

select winner, yr, subject 
from nobel 
where winner like 'Sir%' 
order by yr desc, winner

14.Chemistry and Physics last

SELECT winner, subject 
FROM nobel 
WHERE yr=1984 
ORDER BY subject IN ('Physics','Chemistry'), subject, winner;

Nobel Quiz                                                                                                                                         

1.

SELECT winner FROM nobel
 WHERE winner LIKE 'C%' AND winner LIKE '%n'

2.

SELECT COUNT(subject) FROM nobel
 WHERE subject = 'Chemistry'
   AND yr BETWEEN 1950 and 1960

3.

SELECT COUNT(DISTINCT yr) FROM nobel
 WHERE yr NOT IN (SELECT DISTINCT yr FROM nobel WHERE subject = 'Medicine')

4.

Medicine Sir John Eccles
Medicine Sir Frank Macfarlane Burnet

5.

SELECT yr FROM nobel
 WHERE yr NOT IN(SELECT yr 
                   FROM nobel
                 WHERE subject IN ('Chemistry','Physics'))

6.

SELECT DISTINCT yr
  FROM nobel
 WHERE subject='Medicine' 
   AND yr NOT IN(SELECT yr FROM nobel 
                  WHERE subject='Literature')
   AND yr NOT IN (SELECT yr FROM nobel
                   WHERE subject='Peace')

7.

Chemistry 1
Literature 1
Medicine 2
Peace 1
Physics 1

 

'Algorithm > SQL' 카테고리의 다른 글

[SQL][sqlzoo] SUM and COUNT  (0) 2020.07.02
[SQL][sqlzoo] SELECT within SELECT  (2) 2020.07.02
[SQL][sqlzoo] SELECT from world  (0) 2020.07.02
[SQL][sqlzoo] SELECT basics  (0) 2020.07.02
[SQL][Leetcode] 184. Department Highest Salary  (0) 2020.06.21
profile

융무의 기술블로그

@융무

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!