Wednesday, June 16, 2010

SQL Quiz

Question 1
Table Structure:

nobel(yr, subject, winner)
Name the winner(s) of the Nobel prize in Chemistry in 2001. Sort their names alphabetically.

Question 2
Tables Example:


ttms
gamescolorwhocountry
1988goldYoo Nam-KyuKOR
1988silverKim Ki TaikKOR
........
country
idname
ALGAlgeria
ARGArgentina
......
KORKorea
....
How many medals did each country win in this database? (Make sure to list countries by their name and not their ID.)

11 comments:

  1. fix 1st comment #2 with:
    select country.name, (select count(*) from ttms where ttms.id = country.id) as meds order by meds desc

    ReplyDelete
  2. also fix #1

    select winner form nobel where subject = "Chemistry" and yr = 2001 order by winner

    ReplyDelete
  3. Question 1:
    Select yr-2001, winner
    From nobel
    Where winner In (‘Chemistry’)

    Question 2:
    Korea won 2 medals

    ReplyDelete
  4. 1) SELECT * FROM nobel ORDER BY winner
    2) SELECT country.name , count(*) FROM ttms ORDER BY count(*) DESC

    ReplyDelete
  5. Eddy Huber
    Question 1:
    SELECT * FROM nobel
    WHERE subject = 'Chemistry'
    AND yr = '2001'
    order by winner asc

    Question 2:
    no clue

    ReplyDelete
  6. 1) SELECT winner FROM nobel
    WHERE yr = 2001 AND subject = 'Chemistry'
    order by winner

    2) still working...

    ReplyDelete
  7. select winner from nobel where yr=2001 where subject=chemistry order by winner

    ReplyDelete
  8. select yr, subject, winner
    from nobel
    where yr=2001 and subject='chemistry'
    order by winner desc

    yr subject winner
    2001 Chemistry William S. Knowles
    2001 Chemistry Ryoji Noyori
    2001 Chemistry K. Barry Sharpless

    ReplyDelete
  9. SELECT country.name , count(*) FROM ttms JOIN country ON (ttms.country=country.id) GROUP BY country.name ORDER BY count(*) DESC

    ReplyDelete
  10. SELECT country.name, count(*) FROM ttms
    JOIN country ON (ttms.country = country.id
    )
    GROUP BY country.name

    ReplyDelete