Initial
This commit is contained in:
commit
20a40bd225
10
daten-abfragen/notes.md
Normal file
10
daten-abfragen/notes.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Daten abfragen
|
||||||
|
|
||||||
|
1. Bei Suche nach Daten, die Daten immer in `` ` `` Quotes setzen. Sonst werden die Spalten miteinander verglichen.
|
||||||
|
|
||||||
|
2. MySQL ignoriert Groß- und Kleinschreibung und Ä = A, Ö = O, Ü = U.
|
||||||
|
|
||||||
|
# Syntax
|
||||||
|
`SELECT COUNT(*)` Zählt die Anzahl der Zeilen in einer Tabelle.
|
||||||
|
|
||||||
|
`SELECT DISTINCT ` Gibt nur einzigartige Werte zurück.
|
67
daten-abfragen/select.sql
Normal file
67
daten-abfragen/select.sql
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# use bookstore;
|
||||||
|
|
||||||
|
select *
|
||||||
|
from customers;
|
||||||
|
|
||||||
|
select customers.firstname, customers.lastname, customers.age
|
||||||
|
from customers;
|
||||||
|
|
||||||
|
select count(*)
|
||||||
|
from customers
|
||||||
|
where customers.age > 30;
|
||||||
|
|
||||||
|
select count(*)
|
||||||
|
from customers
|
||||||
|
where customers.age > 30
|
||||||
|
AND customers.age < 40;
|
||||||
|
|
||||||
|
select *
|
||||||
|
from customers
|
||||||
|
where title = 'Frau Dr.'
|
||||||
|
OR title = 'Herr Dr.';
|
||||||
|
|
||||||
|
select *
|
||||||
|
from customers
|
||||||
|
where (title = 'Frau Dr.' OR title = 'Herr Dr.')
|
||||||
|
AND age < 30;
|
||||||
|
|
||||||
|
select count(distinct customers.lastname)
|
||||||
|
from customers;
|
||||||
|
|
||||||
|
select count(customers.age)
|
||||||
|
from customers
|
||||||
|
where age < 30;
|
||||||
|
|
||||||
|
select distinct customers.firstname
|
||||||
|
from customers;
|
||||||
|
|
||||||
|
select distinct customers.firstname, lastname
|
||||||
|
from customers;
|
||||||
|
|
||||||
|
select count(distinct customers.firstname)
|
||||||
|
from customers;
|
||||||
|
|
||||||
|
# Aufgabe SELECT
|
||||||
|
|
||||||
|
select count(*)
|
||||||
|
from baby_names; # 220636
|
||||||
|
|
||||||
|
select count(*)
|
||||||
|
from baby_names
|
||||||
|
where gender = 'm'; # 94322
|
||||||
|
|
||||||
|
select count(distinct baby_names.name)
|
||||||
|
from baby_names; # 6809
|
||||||
|
|
||||||
|
select count(distinct baby_names.name)
|
||||||
|
from baby_names
|
||||||
|
where gender = 'm'; # 2756
|
||||||
|
select count(distinct baby_names.name)
|
||||||
|
from baby_names
|
||||||
|
where gender = 'f'; # 4535
|
||||||
|
|
||||||
|
select *
|
||||||
|
from baby_names
|
||||||
|
where `count` = 19250; # Sandra
|
||||||
|
|
||||||
|
select * from baby_names where gender != 'm' and gender != 'f';
|
16
docker-compose.yml
Normal file
16
docker-compose.yml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mysql:latest
|
||||||
|
container_name: mysql_container
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: root_password
|
||||||
|
MYSQL_DATABASE: bookstore
|
||||||
|
MYSQL_USER: my_user
|
||||||
|
MYSQL_PASSWORD: my_password
|
||||||
|
volumes:
|
||||||
|
- ./sql-scripts:/docker-entrypoint-initdb.d
|
||||||
|
ports:
|
||||||
|
- "3306:3306"
|
||||||
|
restart: unless-stopped
|
301938
sql-scripts/bookstore.sql
Normal file
301938
sql-scripts/bookstore.sql
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user