Announcement

Collapse
No announcement yet.

SQL-Abfrage TOP-3

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • SQL-Abfrage TOP-3

    Hallo allerseits,

    ich habe hier gerade ein kleines Problem mit einer SQL-Abfrage.
    Ausgangssituation:
    - Datenbank: Oracle 10g
    - Tabellen: City, Country, Continent, CountryContinent
    - Beziehung: City in Country, Country in Continent (M:N über CountryContinent)

    Anforderung an Abfrage:
    Zu jedem Kontinent sollen die 3 größten Städte (gemessen an City.Population) angezeigt werden.
    Anzeige: Name der Stadt, Name des Landes, Einwohnerzahl (Stadt)


    Vielen Dank

  • #2
    Hallo,

    das müsste in etwa so gehen:

    Select city.cityname,city.population, country.landname,continent.continentname
    From city,country,continent,continentcountry
    Where city.city_id=country.city_id
    And country.country_id=continentcountry.country_id
    And continent.continent_id=continentcountry.continent_ id
    And not exists
    (select *
    From city as city2,country as country2,continent as continent2,continentcountry as cc2
    Where
    Continentcountry.continent_id=cc2.continent_ID
    And city2.poulation>city.population
    city2.city_id=country2.city_id
    And country2.country_id=cc2.country_id
    And continent2.continent_id=cc2.continent_id
    having count(*)>2)

    Gruß
    docendo discimus

    Comment


    • #3
      Hi !

      hier dazu eine Antwort bei Asktom:

      http://asktom.oracle.com/pls/asktom/...:1212501913138

      Grüsse morlogg

      Comment

      Working...
      X