38 lines
1.3 KiB
SQL
38 lines
1.3 KiB
SQL
select firstname as fn
|
|
from customers;
|
|
|
|
select min(age) as min_age, max(age) as max_age, avg(age) as avg_age
|
|
from customers;
|
|
|
|
select concat(customers.firstname, ' ', lastname) as full_name
|
|
from customers;
|
|
|
|
select upper(concat(customers.firstname, ' ', lastname)) as full_name
|
|
from customers;
|
|
|
|
select length(customers.firstname) as fn_length
|
|
from customers;
|
|
|
|
select concat(customers.firstname, ' ', lastname) as full_name
|
|
from customers
|
|
where length(firstname) = 4; # performance is not perfect
|
|
|
|
# [Aufgabe]: SELECT, LIMIT, ORDER BY
|
|
# Welcher Vorname kam insgesamt (d.h. für ein beliebiges Geschlecht in einem beliebigen Jahr) am häufigsten vor?
|
|
select * from baby_names order by count desc limit 1; # Linda
|
|
select * from baby_names where gender = 'm' and year = 2000 order by count desc limit 1;
|
|
|
|
select min(baby_names.year) from baby_names; # 1880
|
|
|
|
select * from baby_names order by year limit 1; # 1880
|
|
|
|
select count(distinct name) from baby_names where length(name) = 5; # 1590
|
|
|
|
select count(distinct name) from baby_names where name like '_____'; # 1590
|
|
|
|
select sum(count) from baby_names where year = 2000; # 3320671
|
|
|
|
select distinct baby_names.name from baby_names order by baby_names.name asc limit 10, 10; # Aarna
|
|
|
|
|
|
select categories.id, categories.title, replace(title, 'und', '&') from categories; |