Alles erweitert

This commit is contained in:
2026-09-14 14:00:27 +02:00
parent 12515fe2eb
commit b331e333ca
9 changed files with 33230 additions and 109 deletions
+101 -91
View File
@@ -194,6 +194,26 @@ Um anzugeben, wie diese Daten sortiert werden sollen, können wir die `DESC`- od
`ORDER BY avg_speed ASC`
## Datumsangaben behandeln
Daten in SQL haben ein bestimmtes Format und wir können sie ähnlich wie Zahlen abfragen. Um ein Datum in einer Abfrage zu schreiben, verwendet man das Format: YYYY-MM-DD (2012-09-24)
Um Datumsangaben abzufragen, kann man alle Operatoren verwenden, wie – größer (`>`), kleiner (`<`) oder gleich (`=`) innerhalb des Schlüsselworts WHERE:
```sql
SELECT * FROM table1WHERE col1 > '2011-01-13'
```
Wir können sogar das Schlüsselwort BETWEEN verwenden:
```sql
SELECT * FROM table1WHERE col1 BETWEEN '2010-01-01' AND '2010-02-25
```
#############################################################
## Eigenschaften einer Tabelle
```sql
@@ -935,40 +955,38 @@ Das Ergebnis sollte nur die relevanten Sitze enthalten.
Bevor Sie mit der Lösung der Herausforderung beginnen, werfen Sie einen Blick auf die Tabellendaten. **Sie sind nicht sauber**. Die Spalten `is_next_gov` und `is_spoke_bad` enthalten Einsen und Nullen sowie auch yes's und no's.
| ministers | | | |
| :-------: | ---- | ----------- | ------------ |
|:---------:| ---- | ----------- | ------------ |
| | seat | is_next_gov | is_spoke_bad |
| 1 | 1 | 0 | 0 |
| 2 | 2 | 0 | 1 |
| 3 | 3 | yes | no |
| 4 | 4 | no | no |
| 5 | 5 | 1 | no |
| 6 | 6 | yes | no |
| 7 | 7 | 1 | no |
| 8 | 8 | 0 | yes |
| 9 | 9 | 0 | 1 |
| 10 | 10 | no | 1 |
| 11 | 11 | yes | yes |
| 12 | 12 | 1 | 1 |
| 13 | 13 | 1 | 1 |
| 14 | 14 | 1 | 1 |
| 15 | 15 | yes | 0 |
| 16 | 16 | 0 | 0 |
| 17 | 17 | 0 | 0 |
| 18 | 18 | 0 | no |
| 19 | 19 | 1 | yes |
| 20 | 20 | 1 | no |
| 21 | 21 | 0 | 0 |
| 22 | 22 | 1 | 0 |
| 23 | 23 | yes | 1 |
| 24 | 24 | yes | 1 |
| 25 | 25 | no | yes |
| 26 | 26 | 1 | no |
| 27 | 27 | 0 | yes |
| 28 | 28 | yes | no |
| 29 | 29 | no | 0 |
| 30 | 30 | yes | 0 |
| 1 | 1 | 0 | 0 |
| 2 | 2 | 0 | 1 |
| 3 | 3 | yes | no |
| 4 | 4 | no | no |
| 5 | 5 | 1 | no |
| 6 | 6 | yes | no |
| 7 | 7 | 1 | no |
| 8 | 8 | 0 | yes |
| 9 | 9 | 0 | 1 |
| 10 | 10 | no | 1 |
| 11 | 11 | yes | yes |
| 12 | 12 | 1 | 1 |
| 13 | 13 | 1 | 1 |
| 14 | 14 | 1 | 1 |
| 15 | 15 | yes | 0 |
| 16 | 16 | 0 | 0 |
| 17 | 17 | 0 | 0 |
| 18 | 18 | 0 | no |
| 19 | 19 | 1 | yes |
| 20 | 20 | 1 | no |
| 21 | 21 | 0 | 0 |
| 22 | 22 | 1 | 0 |
| 23 | 23 | yes | 1 |
| 24 | 24 | yes | 1 |
| 25 | 25 | no | yes |
| 26 | 26 | 1 | no |
| 27 | 27 | 0 | yes |
| 28 | 28 | yes | no |
| 29 | 29 | no | 0 |
| 30 | 30 | yes | 0 |
select seat from ministers where (seat % 2 = 0) and (is_spoke_bad = 0 or is_spoke_bad = 'no' )and (is_next_gov = 1 or is_next_gov = 'yes');
@@ -991,28 +1009,28 @@ Ein schwerer Krimineller ist jemand, der alle folgenden Kriterien erfüllt:
Benenne die Spalte als `worst_criminals`.
| police_report | | | | |
| :-----------: | ----------------- | ------ | ------------- | ------------ |
|:-------------:| ----------------- | ------ | ------------- | ------------ |
| | name | report | map | severe_score |
| 1 | Domingos Holden | VYyPJw | Lockinge | 2 |
| 2 | Isabel Enid | | Findochty | 7 |
| 3 | Tadgán Musa | FgDqud | Kara's Vale | 10 |
| 4 | Filip Baxter | D1rJqH | Kirkwall | 3 |
| 5 | Edorta Elias | pQ53RC | Dewsbury | 9 |
| 6 | Kəmal Davy | BsI86j | Kara's Vale | 2 |
| 7 | Isokrates Bituin | | Findochty | 5 |
| 8 | Kassy Ramirus | Pkjv7J | Kirkwall | 7 |
| 9 | Doris Blessing | 0kJXq1 | Dalmerlington | 6 |
| 10 | Nedeljka Ganesh | EVe9ha | Kara's Vale | 8 |
| 11 | Karlene Timotheus | 2HUBHz | Dewsbury | 7 |
| 12 | Emerens Raman | PAGdHl | Findochty | 1 |
| 13 | Mijo Ambrosios | | Luton | 5 |
| 14 | Karlene Jairus | 4Z63Q5 | Dalmerlington | 8 |
| 15 | Khordad Peter | | Findochty | 2 |
| 16 | Biagio Mai | | Findochty | 9 |
| 17 | Liwen Sigiward | B51ETs | Mansfield | 3 |
| 18 | Svante Mona | DC0kGh | Caerleon | 5 |
| 19 | Kshitija Ladislav | cSA0hA | Caerleon | 2 |
| 20 | Ha-Eun Tatiana | YNYhHV | Kara's Vale | 4 |
| 1 | Domingos Holden | VYyPJw | Lockinge | 2 |
| 2 | Isabel Enid | | Findochty | 7 |
| 3 | Tadgán Musa | FgDqud | Kara's Vale | 10 |
| 4 | Filip Baxter | D1rJqH | Kirkwall | 3 |
| 5 | Edorta Elias | pQ53RC | Dewsbury | 9 |
| 6 | Kəmal Davy | BsI86j | Kara's Vale | 2 |
| 7 | Isokrates Bituin | | Findochty | 5 |
| 8 | Kassy Ramirus | Pkjv7J | Kirkwall | 7 |
| 9 | Doris Blessing | 0kJXq1 | Dalmerlington | 6 |
| 10 | Nedeljka Ganesh | EVe9ha | Kara's Vale | 8 |
| 11 | Karlene Timotheus | 2HUBHz | Dewsbury | 7 |
| 12 | Emerens Raman | PAGdHl | Findochty | 1 |
| 13 | Mijo Ambrosios | | Luton | 5 |
| 14 | Karlene Jairus | 4Z63Q5 | Dalmerlington | 8 |
| 15 | Khordad Peter | | Findochty | 2 |
| 16 | Biagio Mai | | Findochty | 9 |
| 17 | Liwen Sigiward | B51ETs | Mansfield | 3 |
| 18 | Svante Mona | DC0kGh | Caerleon | 5 |
| 19 | Kshitija Ladislav | cSA0hA | Caerleon | 2 |
| 20 | Ha-Eun Tatiana | YNYhHV | Kara's Vale | 4 |
select name as worst_criminals from police_report where (report like '%g%' or report like '%b%' or report is null ) and map in ('Caerleon', 'Dewsbury', 'Kirkwall', 'Findochty') order by severe_score desc limit 5
@@ -1045,34 +1063,34 @@ Führen Sie diese Schritte aus:
- Dann fast abgelaufene Säfte
- Verwenden Sie (current_year - expiration_year) zum Sortieren
| beverages | | | |
| :-------: | ---- | ------------ | --------------- |
| | id | current_year | expiration_year |
| 1 | 145 | 2013 | 2014 |
| 2 | 156 | 2001 | 2015 |
| 3 | 167 | 2009 | 2004 |
| 4 | 178 | 2005 | 2000 |
| 5 | 124 | 2013 | 2006 |
| 6 | 189 | 2002 | 2014 |
| 7 | 198 | 2007 | 2013 |
| 8 | 201 | 2004 | 2007 |
| 9 | 206 | 2000 | 2000 |
| 10 | 112 | 2011 | 2002 |
| 11 | 209 | 2008 | 2004 |
| 12 | 125 | 2015 | 2012 |
| 13 | 980 | 2008 | 2005 |
| 14 | 402 | 2010 | 2011 |
| 15 | 391 | 2008 | 2009 |
| 16 | 144 | 2015 | 2013 |
| 17 | 213 | 2014 | 2007 |
| 18 | 100 | 2001 | 2000 |
| 19 | 145 | 2002 | 2004 |
| 20 | 981 | 2011 | 2014 |
| 21 | 210 | 2002 | 2007 |
| 22 | 392 | 2010 | 2006 |
| 23 | 393 | 2007 | 2013 |
| 24 | 113 | 2010 | 2002 |
| 25 | 255 | 2001 | 2008 |
| beverages | | | |
|:---------:| --- | ------------ | --------------- |
| | id | current_year | expiration_year |
| 1 | 145 | 2013 | 2014 |
| 2 | 156 | 2001 | 2015 |
| 3 | 167 | 2009 | 2004 |
| 4 | 178 | 2005 | 2000 |
| 5 | 124 | 2013 | 2006 |
| 6 | 189 | 2002 | 2014 |
| 7 | 198 | 2007 | 2013 |
| 8 | 201 | 2004 | 2007 |
| 9 | 206 | 2000 | 2000 |
| 10 | 112 | 2011 | 2002 |
| 11 | 209 | 2008 | 2004 |
| 12 | 125 | 2015 | 2012 |
| 13 | 980 | 2008 | 2005 |
| 14 | 402 | 2010 | 2011 |
| 15 | 391 | 2008 | 2009 |
| 16 | 144 | 2015 | 2013 |
| 17 | 213 | 2014 | 2007 |
| 18 | 100 | 2001 | 2000 |
| 19 | 145 | 2002 | 2004 |
| 20 | 981 | 2011 | 2014 |
| 21 | 210 | 2002 | 2007 |
| 22 | 392 | 2010 | 2006 |
| 23 | 393 | 2007 | 2013 |
| 24 | 113 | 2010 | 2002 |
| 25 | 255 | 2001 | 2008 |
```sql
SELECT id as to_renew
@@ -1081,16 +1099,12 @@ WHERE current_year - expiration_year > 6 OR current_year = expiration_year OR ex
ORDER by current_year-expiration_year DESC
```
## Wiederholung – Neue Spalten erstellen
### Challenge
> Verfügbare Tabellen und Spalten:
>
>
> - `items`**:** `id`
Eine quartische Funktion ist definiert:
@@ -1121,8 +1135,4 @@ a*a*a
-- Potenz von 3
```
`select id , (3*id*id*id*id + 5*id*id*id + 0.9*id*id + 2.2 * id +1 )as quartic from items`