Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Převod na formát kodim 2.0 #8

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion entry.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
title: Datová analytika
lead: Kurz SQL - Digitální akademie data. Lekce SQL nad Snowflake/Keboola.
image: intro-image.svg
image: assets/intro-image.svg
chapters:
- sql
18 changes: 9 additions & 9 deletions sql/vyuka/cviceni-01.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ V úkolech budeme pracovat s tabulkou `TEROR` ve schématu `SCH_TEROR`.
INT_MISC, INT_ANY, RELATED
```

::exc[cviceni>01-01-vyber-vse]
::exc[cviceni>01-02-deset-radku]
::exc[cviceni>01-03-tri-sloupce]
::exc[cviceni>01-04-unikatni-roky]
::exc[cviceni>01-05-2016]
::exc[cviceni>01-06]
::exc[cviceni>01-07]
::exc[cviceni>01-08]
::exc[cviceni>01-09]
::exc[cviceni/01-01-vyber-vse]
::exc[cviceni/01-02-deset-radku]
::exc[cviceni/01-03-tri-sloupce]
::exc[cviceni/01-04-unikatni-roky]
::exc[cviceni/01-05-2016]
::exc[cviceni/01-06]
::exc[cviceni/01-07]
::exc[cviceni/01-08]
::exc[cviceni/01-09]
24 changes: 12 additions & 12 deletions sql/vyuka/cviceni-02.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

V úkolech budeme pracovat s tabulkou `TEROR` ve schématu `SCH_TEROR`.

::exc[cviceni>02-01]
::exc[cviceni>02-02]
::exc[cviceni>02-03]
::exc[cviceni>02-04]
::exc[cviceni>02-05]
::exc[cviceni>02-06]
::exc[cviceni>02-07]
::exc[cviceni>02-08]
::exc[cviceni>02-09]
::exc[cviceni>02-10]
::exc[cviceni>02-11]
::exc[cviceni>02-12]
::exc[cviceni/02-01]
::exc[cviceni/02-02]
::exc[cviceni/02-03]
::exc[cviceni/02-04]
::exc[cviceni/02-05]
::exc[cviceni/02-06]
::exc[cviceni/02-07]
::exc[cviceni/02-08]
::exc[cviceni/02-09]
::exc[cviceni/02-10]
::exc[cviceni/02-11]
::exc[cviceni/02-12]
14 changes: 7 additions & 7 deletions sql/vyuka/cviceni-03.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

V úkolech budeme pracovat s tabulkou `TEROR` ve schématu `SCH_TEROR`.

::exc[cviceni>03-01]
::exc[cviceni>03-02]
::exc[cviceni>03-03]
::exc[cviceni>03-04]
::exc[cviceni>03-05]
::exc[cviceni>03-06]
::exc[cviceni>03-07]
::exc[cviceni/03-01]
::exc[cviceni/03-02]
::exc[cviceni/03-03]
::exc[cviceni/03-04]
::exc[cviceni/03-05]
::exc[cviceni/03-06]
::exc[cviceni/03-07]
12 changes: 6 additions & 6 deletions sql/vyuka/cviceni-04.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

V úkolech budeme pracovat

::exc[cviceni>04-01]
::exc[cviceni>04-02]
::exc[cviceni>04-03]
::exc[cviceni>04-04]
::exc[cviceni>04-05]
::exc[cviceni>04-06]
::exc[cviceni/04-01]
::exc[cviceni/04-02]
::exc[cviceni/04-03]
::exc[cviceni/04-04]
::exc[cviceni/04-05]
::exc[cviceni/04-06]
10 changes: 5 additions & 5 deletions sql/vyuka/cviceni-05.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Pokud nevíte, jak naimportovat data, nebo jste se na tom zasekli, tak [tady je

**Nedoporučujeme** se na to vykašlat a jet rovnou podle návodu, z toho si odnesete velmi málo. 😉

::exc[cviceni>05-01]
::exc[cviceni>05-02]
::exc[cviceni>05-03]
::exc[cviceni>05-04]
::exc[cviceni>05-05]
::exc[cviceni/05-01]
::exc[cviceni/05-02]
::exc[cviceni/05-03]
::exc[cviceni/05-04]
::exc[cviceni/05-05]
6 changes: 3 additions & 3 deletions sql/vyuka/cviceni-06.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

Vnořené dotazy a CTE

::exc[cviceni>06-01]
::exc[cviceni>06-02]
::exc[cviceni>06-03]
::exc[cviceni/06-01]
::exc[cviceni/06-02]
::exc[cviceni/06-03]
6 changes: 3 additions & 3 deletions sql/vyuka/cviceni-07.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

Vnořené dotazy a CTE

::exc[cviceni>07-01]
::exc[cviceni>07-02]
::exc[cviceni>07-03]
::exc[cviceni/07-01]
::exc[cviceni/07-02]
::exc[cviceni/07-03]
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/01-01-vyber-vse.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Vyber vše z tabulky teror.

---solution
:::solution

- Všechny řádky vybereme tím, že nezadáme žádnou podmínku. Abychom vybrali všechny sloupce, můžeme použít hvězdičku.

Expand Down Expand Up @@ -81,3 +81,5 @@ Vyber vše z tabulky teror.
FROM TEROR
WHERE 1 = 1;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/01-02-deset-radku.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ demand: 2

Zobraz (náhodných) deset řádků z tabulky teror.

---solution
:::solution

```sql
SELECT * FROM teror
LIMIT 10;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/01-03-tri-sloupce.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ demand: 1
---

Vypiš jen sloupce EVENTID, IYEAR, COUNTRY_TXT, REGION_TXT.
---solution
:::solution

- Abychom vybrali jen čtyři sloupce, musíme je vyjmenovat

Expand Down Expand Up @@ -46,3 +46,5 @@ Vypiš jen sloupce EVENTID, IYEAR, COUNTRY_TXT, REGION_TXT.

FROM TEROR;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/01-04-unikatni-roky.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Vypiš všechny roky vyskytující se v tabulce teror, tak aby byl každý rok ve výsledné tabulce jen jednou.

---solution
:::solution

Abychom vybrali pouze jeden sloupec, napíšeme jeho jméno:

Expand All @@ -23,3 +23,5 @@ Anebo je všechny _zgroupovat_ podle IYEAR:
```

Tato varianta bude fungovat, ale je zbytečně složitá a pokud se nedotazujete na nic složitějšího, tak nedoporučujeme. 😉

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/01-05-2016.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Vyber všechny teroristické útoky v roce 2016.

---solution
:::solution

Abychom vybrali všechny teroristické útoky v roce 2016, musíme použít filtr na sloupec IYEAR:

Expand All @@ -20,3 +20,5 @@ nebo funkci DATE_PART nad sloupcem IDATE
SELECT * FROM TEROR
WHERE DATE_PART(YEAR, IDATE) = 2016;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/01-06.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Vypiš všechny útoky za rok 2015 a vyber pouze sloupce EVENTID, IYEAR, COUNTRY_TXT, REGION_TXT a přejmenuj je na UDALOST, ROK, ZEME, REGION.

---solution
:::solution

```sql
SELECT EVENTID AS UDALOST,
Expand All @@ -15,3 +15,5 @@ Vypiš všechny útoky za rok 2015 a vyber pouze sloupce EVENTID, IYEAR, COUNTRY
FROM TEROR
WHERE IYEAR=2015;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/01-07.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Vyber všechny události v roce 2014 a vyber pouze sloupce IYEAR, IMONTH A IDAY. Spoj je do jednoho sloupce oddělené pomlčkou a pojmenuj ho DATUM.

---solution
:::solution

- Sloupečky můžeme spojit spojovátkem `||`:

Expand All @@ -22,3 +22,5 @@ Vyber všechny události v roce 2014 a vyber pouze sloupce IYEAR, IMONTH A IDAY.
FROM TEROR
WHERE IYEAR=2014;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/01-08.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Seřaď datum z předchozího selektu sestupně (desc) a vypiš jen jedinečné záznamy.

---solution
:::solution

Sloupečky můžeme spojit spojovátkem `||`:

Expand All @@ -24,3 +24,5 @@ Sloupečky můžeme spojit funkcí `CONCAT`:
WHERE IYEAR=2014
ORDER BY DATUM DESC;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/01-09.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Vypiš počet teroristických útoků, které se staly po roce 2015 (52243).

---solution
:::solution

a)

Expand All @@ -24,3 +24,5 @@ b)
WHERE DATE_PART(YEAR, IDATE) > 2015;
-- 52243
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/02-01.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ demand: 1

Vyber z tabulky `TEROR` útoky v Německu, kde zemřel alespoň jeden terorista.

---solution
:::solution

```sql
SELECT *
FROM TEROR
WHERE NKILLTER > 0
AND COUNTRY_TXT = 'Germany';
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/02-02.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Zobraz jen sloupečky GNAME, COUNTRY_TXT, NKILL a všechny řádky (seřazené podle počtu mrtvých sestupně), na kterých je víc než 340 mrtvých (počet mrtvých je ve sloupci NKILL), sloupečky přejmenuj na ORGANIZACE, ZEME, POCET_MRTVYCH.

---solution
:::solution

```sql
SELECT
Expand All @@ -16,3 +16,5 @@ FROM teror
WHERE nkill > 340
ORDER BY POCET_MRTVYCH DESC;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/02-03.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Zobraz sloupečky IYEAR, IMONTH, IDAY, GNAME, CITY, ATTACKTYPE1_TXT, TARGTYPE1_TXT, WEAPTYPE1_TXT, WEAPDETAIL, NKILL, NWOUND a vyber jen útoky, které se staly v Czech Republic v letech 2015, 2016 a 2017. Všechna data seřaď chronologicky sestupně.

---solution
:::solution

```sql
SELECT IYEAR,
Expand All @@ -26,3 +26,5 @@ ORDER BY IYEAR DESC,
IMONTH DESC,
IDAY DESC;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/02-04.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ demand: 1

Vypiš všechny organizace, které na jakémkoliv místě v názvu obsahují výraz „anti“ a výraz „extremists“.

---solution
:::solution

```sql
SELECT DISTINCT GNAME
FROM TEROR
WHERE GNAME ILIKE '%anti%'
AND GNAME ilike '%extremists%';
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/02-05.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Z IYEAR, IMONTH a IDAY vytvořte sloupeček datum a vypište tohle datum a pak datum o tři měsíce později a klidně i o tři dny a tři měsíce.

---solution
:::solution

```sql
SELECT DATE_FROM_PARTS(IYEAR, IMONTH, IDAY) DATUM,
Expand All @@ -20,3 +20,5 @@ SELECT DATE_FROM_PARTS(IYEAR, IMONTH, IDAY) DATUM,
) O_TRI_MESICE_A_TRI_DNY_POZDEJI
FROM TEROR;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/02-06.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ demand: 1

Vypiš všechny druhy útoků ATTACKTYPE1_TXT.

---solution
:::solution

```sql
SELECT DISTINCT ATTACKTYPE1_TXT
FROM TEROR;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/02-07.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Vypiš všechny útoky v Německu v roce 2015, vypiš sloupečky IYEAR, IMONTH, IDAY, COUNTRY_TXT, REGION_TXT, PROVSTATE, CITY, NKILL, NKILLTER, NWOUND. Ve sloupečku COUNTRY_TXT bude všude hodnota ‘Německo’

---solution
:::solution

```sql
SELECT IYEAR AS ROK,
Expand All @@ -23,3 +23,5 @@ FROM TEROR
WHERE COUNTRY_TXT = 'Germany'
AND IYEAR = 2015;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/02-08.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Kolik událostí se stalo ve třetím a čtvrtém měsíci a počet mrtvých teroristů není NULL?

---solution
:::solution

```sql
SELECT COUNT(*)
Expand All @@ -31,3 +31,5 @@ WHERE (
)
AND NKILLTER IS NOT NULL;
```

:::
4 changes: 3 additions & 1 deletion sql/vyuka/cviceni/02-09.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ demand: 1

Vypiš první 3 města seřazena abecedně, kde bylo zabito 30 až 100 teroristů nebo zabito 500 až 1000 lidí. Vypiš i sloupečky nkillter a nkill.

---solution
:::solution

```sql
SELECT
Expand Down Expand Up @@ -36,3 +36,5 @@ WHERE (
ORDER BY CITY
LIMIT 3;
```

:::
Loading
Loading