1

I am new to databases. And our teacher gave us pretty hard assignment. There are two tables. First table nickname is abilities(of superhero's:) ) and second table name superheros.

We have to select nick of Superhero and his average(medial) range for those who has two abilities?

Image of both tables:

http://postimg.org/image/85pqbc47n/

Original here: http://postimg.org/image/85pqbc47n/

4

2 回答 2

2

I will not give you solution - after all, it's homework and you have to learn something :) But I can give you an advice - try to do one task at a time

  • first, find those superheroes who has only 2 abilities (actually, you can do this by quering only table with abilities)
  • second - try to find average range of abilities for all superheroes (here you'll need join)
  • combine your queries

take a look at join, group by, count and having

Don't feel bad if you can't write it at first attempt, your query is not super easy, but 'm sure you can do this.

于 2013-09-01T18:59:15.947 回答
0

You can use HAVING and AVG() for this:

SELECT s.NickName, AVG(a.Range)
FROM abilities a
JOIN superhero s
 ON a.ID_SuperHero = s.ID_SuperHero
GROUP BY s.NickName
HAVING COUNT(DISTINCT a.Abilities > 1)
于 2013-09-01T19:03:30.827 回答