Initial
This commit is contained in:
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';
|
Reference in New Issue
Block a user