Estudiante
Ejercicio 5. Listar por categoría el número de productos y el costo total de la ganancia de todos los productos de esa categoría.
select c.cat_descripcion as Categoria_Producto, --esta linea muestra la categoria del producto
count(*)as Numero_Producto,--esta linea cuenta todos los producto
sum(stock * costoventa) as Ganancia --muestra y hace la suma de la gananciade cada producto
from fer_categoria c, --elegimos la tabla fer_categoria con un alias llamado c
fer_ganancia g, --elegimos la tabla fer_ganancia con un alias llamado g
fer_producto p --elegimos la tabla fer_producto con un alias llamado p
where c.cat_id = g.gan_cat_id --cruzamos el id de la tablas fer_categoria contra fer_ganancia
and c.cat_id = p.pro_cat_id --cruzamos el id dela tablas fer_categoria contra fer_producto
group by c.cat_descripcion --aqui agrupamos por cat_descripcion
order by 1 --ordenamos por cat_descripcion
Ejercicio 6. Listar por categoría el máximo precio del producto.
select c.cat_descripcion descripcion,
--p.pro_descripcion producto,
max(cp.cpro_costo_venta)
from fer_categoria c,
fer_producto p,fer_costo_producto cp
where c.cat_id=p.pro_cat_id
and p.pro_id=cp.cpro_pro_id
and cp.cpro_estado = 'A'
group by c.cat_descripcion
order by 1,2
Trabajando en el from anidadas
select catemaxprecio.Categoria,
categoriaProducto.NombreProducto,
catemaxprecio.maximoprecio
from
(
select c.cat_descripcion as categoria,max(cp.cpro_costo_venta) maximoprecio
from fer_categoria c,
fer_producto p,
fer_costo_producto cp
where c.cat_id=p.pro_cat_id
and p.pro_id=cp.cpro_pro_id
and cp.cpro_estado = 'A'
group by c.cat_descripcion
)catemaxprecio,-------------------continuacion del from de arriba-----------------------------
(
select c.cat_descripcion as categoria,
p.pro_descripcion NombreProducto,
cp.cpro_costo_venta PrecioProducto
from fer_categoria c,
fer_producto p,
fer_costo_producto cp
wherec.cat_id=p.pro_cat_id
and p.pro_id=cp.cpro_pro_id
and cp.cpro_estado = 'A'
order by 1,2
)categoriaProducto
where catemaxprecio.Categoria=categoriaProducto.Categoria
and catemaxprecio.maximoprecio=categoriaProducto.PrecioProducto
---------Utilizando en el where---------
select c.cat_descripcion Descripcion,
p.pro_descripcion Producto,cp.cpro_costo_venta MaximoPrecio
from fer_categoria c,
fer_producto p,
fer_costo_producto cp
where c.cat_id=p.pro_cat_id
and p.pro_id=cp.cpro_pro_id
and cp.cpro_estado = 'A'
and (c.cat_descripcion,cp.cpro_costo_venta)in
---------------------------------------------------------
(select c.cat_descripcion as categoria,max(cp.cpro_costo_venta) maximoprecio
from fer_categoria c,
fer_producto p,
fer_costo_producto cp
where c.cat_id=p.pro_cat_id
and p.pro_id=cp.cpro_pro_id
and cp.cpro_estado = 'A'
group by c.cat_descripcion )
En el esquema de facturación
Ejercicio 7. Generar un listado deempleados con el número de comprobantes tipo factura que han sido cobrados, y los clientes con el número de comprobantes pagados. Indicar el nombre, así sea el número de comprobantes sea igual a cero.
select p.per_nombre_razon_social nombre, 'Empleado' as Tipo,
(select count (tc.tcp_id)
from fer_comprobante c,
fer_tipo_comprobante tc...
Regístrate para leer el documento completo.