You are on page 1of 3

SQL Ejercicios

Seleccionar Empleados donde el primer nombre NO sea marta


select *
from s_emp
where first_name <> 'Marta'
Que empleados pertenecen a la region de Asia
SELECT userid
FROM s_emp
WHERE dept_id IN(
SELECT id
FROM s_dept
WHERE region_id IN(
SELECT id
FROM s_region
WHERE name = 'Asia'
)

)
Listar el empleado de menor salario
SELECT first_name,last_name
FROM s_emp
WHERE salary IN
(
SELECT min(salary)
FROM s_emp
)

Contar cuantos clients hay por ciudad


SELECT count(id),city
FROM s_customer
group by city
mostrar el nombre del cliente con el nombre de region y que el nivel del cliente sea
GOOD
select a.name,b.name
from s_customer a,s_region b
where a.region_id=b.id
and a.credit_rating = 'GOOD'
listar datos de los empleados cuyo salario es mayor al promedio
SELECT *
FROM s_emp
WHERE salary >
(
SELECT avg(salary)
FROM s_emp
)

Nombre de las orden con mas cantidad en su total


SELECT id
FROM s_ord
WHERE total >= ALL (SELECT total
FROM s_ord);
SELECT id
FROM s_ord
WHERE total = (SELECT MAX(total)
FROM s_ord);

Nombre de clients que viven en el pais con mas gente


SELECT *
FROM s_customer
WHERE country IN (SELECT country
FROM s_customer
GROUP BY country
HAVING COUNT(*) >= ALL (SELECT COUNT(*)
FROM s_customer
GROUP BY country));
SELECT *
FROM s_customer
WHERE country IN (SELECT country
FROM s_customer
GROUP BY country
HAVING COUNT(*) < ANY (SELECT COUNT(*)
FROM s_customer
GROUP BY country));

You might also like