SQL Flashcards
Selecione as colunas da tabela “actor” e filtre pelos nomes iniciados pela letra A
use o comando LIKE
select *
from actor
where first_name like ‘a%’
lllllllllllllllllllllllllllllllllll
Selecione as colunas da tabela “actor” e filtre apenas os 10 primeiros resultados
use o comando LIMIT
select *
from actor
limit 10
llllllllllllllllllllllllllllllllllllllllllllllllllll
Selecione as colunas da tabela “actor” e filtre os resultados de 6 a 15
use o comando LIMIT
select *
from actor
limit 5, 10
llllllllllllllllllllllllllllllllllllllllllllllllllll
Selecione as colunas da tabela “actor” e filtre os resultados que contenham a letra A
use o comando REGEXP
select *
from actor
where first_name regexp ‘a’
lllllllllllllllllllllllllllllllll
Selecione as colunas da tabela “actor” e filtre os resultados que comecem com a letra A
use o comando REGEXP
select *
from actor
where first_name regexp ‘^a’
lllllllllllllllllllllllllllllllll
Selecione as colunas da tabela “actor” e filtre os resultados que comecem com a letra A e com a letra C
use o comando REGEXP
select *
from actor
where first_name regexp ‘^a|^c’
lllllllllllllllllllllllllllllllll
Selecione as colunas da tabela “actor” e filtre os resultados que comecem com as letras CA, DA e SA
use o comando REGEXP
select *
from actor
where first_name regexp ‘^[cds]a’
llllllllllllllllllllllllllll
Selecione as colunas da tabela “address” e filtre os resultados cujo distrito seja California, Buenos Aires ou England
use o comando IN
select *
from address
where district in (‘California’, ‘Buenos Aires’, ‘England’)
Selecione as colunas
“customer_id”, “first_name” e “last_name” da tabela “customer”
e una com as colunas
“rental_id” e “amount” da tabela “payment”
use o comando JOIN
use ALIAS para nomear as tabelas CUSTOMER e PAYMENT
select
customer.customer_id,
customer.first_name,
customer.last_name,
payment.rental_id,
payment.amount
from customer
join payment on customer.customer_id = payment.payment_id
Insira um novo idioma na tabela “language”
insert into language
values (
default,
‘Portuguese’,
‘2006-02-15 05:02:20’
)
Insira uma nova cidade na tabela “city”
insert into city
values (
default,
‘Três Corações’,
15,
‘2023-09-26 16:45:00’
)
Crie uma cópia de uma tabela
create table payment_backup as
select * from payment
lllllllllllllllllllllllllllll
Atualize o valor da coluna “amount” da tabela PAYMENT, cujo payment_id é igual a 1
update payment
set amount = 8.99
where payment_id = 1
llllllllllllllllllllllll
Delete um registro de alguma tabela
DELETE FROM payment
WHERE payment_id = 16049
lllllllllllllllllllllllllllllllllllll
Liste o menor valor, o maior valor, a média, soma e o número de vendas do funcionário 1
SELECT
MAX(amount) as “Valor máximo”,
MIN(amount) as “Valor mínimo”,
AVG(amount) as “Média”
SUM(amount) as “Vendas Totais”
COUNT(amount) as “Número de vendas”
FROM payment
WHERE staff_id = 1