Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung | |||
faecher:informatik:oberstufe:datenbanken:sql_gruppierungen:lsg:start [10.11.2020 09:32] – sbel | faecher:informatik:oberstufe:datenbanken:sql_gruppierungen:lsg:start [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== Gruppierungen: | ||
- | |||
- | **(1)** | ||
- | |||
- | ^Funktion ^ Bedeutung ^ Wert in Gruppe '' | ||
- | | AVG | Durchschnittlicher Bestand in der den Preiskategorien | ||
- | | COUNT | ||
- | | MAX | ||
- | | MIN | ||
- | | SUM | ||
- | |||
- | |||
- | |||
- | **(2)** | ||
- | |||
- | (i) | ||
- | |||
- | <code sql> | ||
- | SELECT APreis, SUM(ABestand) AS Bestandssumme | ||
- | FROM `artikel` | ||
- | WHERE APreis <= 10 | ||
- | GROUP BY Apreis | ||
- | ORDER BY APreis, | ||
- | </ | ||
- | |||
- | (ii) Gruppiert wird nach APreis und nach ABestand, in der ersten Spalte kann man sich zusätzlich mit '' | ||
- | |||
- | <code sql> | ||
- | SELECT COUNT(*), APreis, ABestand | ||
- | FROM artikel | ||
- | GROUP BY APreis, ABestand | ||
- | </ | ||
- | |||
- | (iii) Die Abfrage ermittelt die Zahl der Datensätze, | ||
- | |||
- | (v) Liegt die Filterbedingung, | ||
- | |||
- | <code sql> | ||
- | SELECT APreis, SUM(ABestand) AS Bestandssumme | ||
- | FROM `artikel` | ||
- | WHERE APreis <= 10 | ||
- | GROUP BY APreis | ||
- | </ | ||
- | |||
- | <code sql> | ||
- | SELECT APreis, SUM( ABestand ) AS Bestandssumme | ||
- | FROM `artikel` | ||
- | GROUP BY APreis | ||
- | HAVING APreis <=10 | ||
- | LIMIT 0 , 30 | ||
- | </ | ||
- | |||
- | **Allgemein: | ||
- | |||
- | <code sql> | ||
- | SELECT ABestand, AVG(APreis) AS Mittelpreis | ||
- | FROM artikel | ||
- | GROUP BY ABestand | ||
- | WHERE Mittelpreis < 10 | ||
- | </ | ||
- | |||
- | <code sql> | ||
- | SELECT ABestand, AVG(APreis) AS Mittelpreis | ||
- | FROM artikel | ||
- | GROUP BY ABestand | ||
- | HAVING Mittelpreis < 10 | ||
- | </ | ||
- | |||
- | |||
- | Die Aufgabe (v) lässt sich also nicht mit WHERE lösen, da man dabei immer nur für eine Zeile das Produkt aus Bestand und Preis betrachten kann - man möchte aber für eine ganze Kategorie die Bestanddsumme * Artikelpreis anschauen und danach auch Filtern: | ||
- | |||
- | <code sql> | ||
- | SELECT APreis, SUM(`ABestand`)*APreis AS Umsatz | ||
- | FROM artikel | ||
- | GROUP BY APreis HAVING Umsatz >= 3000 | ||
- | </ | ||