Created: 2025-01-30 jue 19:04
fromHavingfromwheregroup byhavingorder byselectselect
location, count(*) as ocupacion
from
section
where
capacity > 10
group by
location
having
count(*) < 10
order by
ocupacion;
upper, lower: Mayúsculas y minúsculastrunc: quita decimales a números, horas y minutos a las fechasmod, sqrt…: funciones matemáticasto_number: Convierte una cadena a númeroextract: Extrae partes de una fechanvl: Pone un valor por defecto si un valor es nullselect sysdate - interval '1' month + interval '1' day from dual;
to_char: Formatea fechas o números y los convierte en cadenasinstr: Busca el comienzo de una cadena dentro de otra cadenato_date: Convierte una cadena en una fechasubstr: partes de un varcharregexp_like: como like, pero con expresiones regularesavg: mediamax: mínimomin: máximosum: sumacount: cuenta valores de columnascount(distict ): cuenta valores distintoscount(*): cuenta todas las filas, incluidos los valores nullPrecio depende de parte de la clave)| Producto | Precio | Cantidad | Fecha pedido | Cliente |
|---|---|---|---|---|
| Pera | 1 | 2 | 1-1 | Pepe |
| Manzana | 2 | 4 | 1-1 | Pepe |
| Naranja | 3 | 3 | 1-1 | María |
| Manzana | 2 | 6 | 1-2 | María |
| Pera | 1 | 5 | 1-2 | Juan |
| Naranja | 3 | 3 | 1-2 | Juan |
| Producto | Precio |
|---|---|
| Pera | 1 |
| Manzana | 2 |
| Naranja | 3 |
| Producto | Cantidad | Fecha pedido | Cliente |
|---|---|---|---|
| Pera | 2 | 1-1 | Pepe |
| Manzana | 4 | 1-1 | Pepe |
| Naranja | 3 | 1-1 | María |
| Manzana | 6 | 1-2 | María |
| Pera | 5 | 1-2 | Juan |
| Naranja | 3 | 1-2 | Juan |
| PRODUCTO.producto | PRODUCTO.precio | PEDIDOS.producto | PEDIDOS.cantidad | PEDIDOS.Fecha pedido | PEDIDOS.cliente |
|---|---|---|---|---|---|
| Pera | 1 | Pera | 2 | 1-1 | Pepe |
| Pera | 1 | Manzana | 4 | 1-1 | Pepe |
| Pera | 1 | Naranja | 3 | 1-1 | María |
| Pera | 1 | Manzana | 6 | 1-2 | María |
| Pera | 1 | Pera | 5 | 1-2 | Juan |
| Pera | 1 | Naranja | 3 | 1-2 | Juan |
| Manzana | 2 | Pera | 2 | 1-1 | Pepe |
| Manzana | 2 | Manzana | 4 | 1-1 | Pepe |
| Manzana | 2 | Naranja | 3 | 1-1 | María |
| Manzana | 2 | Manzana | 6 | 1-2 | María |
| Manzana | 2 | Pera | 5 | 1-2 | Juan |
| Manzana | 2 | Naranja | 3 | 1-2 | Juan |
| Naranja | 3 | Pera | 2 | 1-1 | Pepe |
| Naranja | 3 | Manzana | 4 | 1-1 | Pepe |
| Naranja | 3 | Naranja | 3 | 1-1 | María |
| Naranja | 3 | Manzana | 6 | 1-2 | María |
| Naranja | 3 | Pera | 5 | 1-2 | Juan |
| Naranja | 3 | Naranja | 3 | 1-2 | Juan |
where PRODUCTO.producto = PEDIDOS.producto| PRODUCTO.producto | PRODUCTO.precio | PEDIDOS.producto | PEDIDOS.cantidad | PEDIDOS.Fecha pedido | PEDIDOS.cliente |
|---|---|---|---|---|---|
| Pera | 1 | Pera | 2 | 1-1 | Pepe |
| Pera | 1 | Pera | 5 | 1-2 | Juan |
| Manzana | 2 | Manzana | 4 | 1-1 | Pepe |
| Manzana | 2 | Manzana | 6 | 1-2 | María |
| Naranja | 3 | Naranja | 3 | 1-1 | María |
| Naranja | 3 | Naranja | 3 | 1-2 | Juan |
select
*
from
PRODUCTOS,PEDIDOS
where
PRODUCTOS.producto = PEDIDOS.producto;
select
*
from
PRODUCTOS join PEDIDOS on PRODUCTOS.producto = PEDIDOS.producto;
select, extrayendo información de las tablas originalescreate view ALUMNOS as
select student_id as clave, first_name as nombre, last_name as apellidos from student;
select * from alumnos;
fromfrom no es obligatorio poner tablasselect * from (
select student_id as clave, first_name as nombre, last_name as apellidos from student
);
fromselect nombre, apellidos from (
select student_id as clave, first_name as nombre, last_name as apellidos from student
)
where clave > 10;
with estudiantes as(
select student_id as clave, first_name as nombre, last_name as apellidos from student
)
select nombre, apellidos
from estudiantes
where clave > 10;
select * from student
where upper(last_name) = (
select max(upper(last_name)) from student
);
inselect distinct course_no from section where capacity = 25 order by course_no;
select * from course where course_no = 20 or course_no = 220 or course_no = 134;
select * from course where course_no in (20,220,134);
select * from course where course_no in (
select distinct course_no from section where capacity = 25
);
Havinghaving sirve para poner condiciones a los grupos de una consultafromselect * from
(
select
location, count(*) as ocupacion
from
section
group by
location
)
where ocupacion < 10;
select
location, count(*) as ocupacion
from
section
group by
location
having
count(*) < 10;
unionintersectminus
with student_con_orden as(
select rownum as orden, student.*
from student
order by last_name
)
select * from student_con_orden where orden > 100 and orden < 200;
select Student.*
from student
order by last_name
offset 0 rows -- offset es opcional
FETCH next 1 rows with ties; -- rows only