English version (when available)
select linea, articulo, (importe*cantidad) total from linped where numPedido=1;
select count(distinct provincia) provincias from usuario;
select count(*) usuarios from usuario;
select count(*) from articulo where pvp>200;
select sum(pvp) total from cesta, articulo where usuario='bmm@agwab.com' and articulo=cod;
select MAX(pantalla) maxPantalla from tv;
select round(avg(distinct pvp),2) mediaventa from articulo;
select nombre,pvp from articulo,stock where cod=articulo and disponible = (select min(disponible) from stock);
select p.numPedido,fecha,nombre,apellidos from pedido p,linped l,usuario u where p.usuario=email and p.numPedido=l.numPedido and (cantidad*importe)=(select max(cantidad*importe) from linped);
select MAX(pvp) maxPvp, MIN(pvp) minPvp, AVG(pvp) mediaPvp from articulo;
select cod, nombre, pvp, fecha from cesta, articulo where articulo=cod and fecha=(select MAX(fecha) from cesta);
select count(*) NumArtDescatalogados from stock where entrega='Descatalogado'
select max(pvp) from articulo, stock where cod=articulo and entrega='Próximamente';
select nombre, cod, disponible MinDisponible from stock, articulo where articulo=cod and cod like '%3' and disponible=(select MIN(disponible) from stock);
select MAX(importe) MaxPrecio, MIN(importe) MinPrecio, AVG(importe) PrecioMedio from linped l, articulo a where a.cod=l.articulo and a.nombre='Bravia KDL-32EX402';
select SUM(cantidad) cantidadTotal from linped, articulo where articulo=cod and nombre like 'UE22%';
select round(avg(importe),3) PrecioMedio from linped where linea=4;
select l.numPedido, nombre, telefono, email from usuario u, pedido p, linped l where l.numPedido=p.numPedido and p.usuario=u.email and importe=(select MAX(importe) from linped where linea=2);Primero se ha de calcular el precio máximo de entre todas las segundas líneas (la subconsulta) y, entonces, ya se pueden comparar TODAS las líneas de pedido: saldrá, seguro, el pedido de esa segunda línea que da el máximo, pero ese precio máximo se puede repetir en cualquier otra línea.
select (MAX(importe)-MIN(importe)) DiferenciaPrecios from linped where numPedido=30;
select cod,nombre,pvp from articulo,stock where cod=articulo and disponible = (select MAX(disponible) from stock);
select MIN(nacido) from usuario;
select count(*) filas, count(marca) conmarca, count(distinct marca) marcas from articulo;
select cod, nombre, marca from articulo where pvp = (select max(pvp) from articulo);Solución alternativa:La solución alternativa no funciona en versiones antiguas de MySQL por un "bug".select cod, nombre, marca from articulo where pvp >= all (select pvp from articulo);
select a.cod, nombre, pvp from articulo a, camara c where a.cod=c.cod and tipo like '%reflex%' and pvp=( select max(pvp) from articulo a, camara c where a.cod=c.cod and tipo like '%reflex%');Solución alternativa:select a.cod, nombre, pvp from articulo a, camara c where a.cod=c.cod and tipo like'%réflex%' and pvp >= all (select pvp from articulo a, camara c where a.cod=c.cod and tipo like'%réflex%');
select cod,nombre,disponible from stock, articulo where cod=articulo and entrega='24 horas' and disponible=(select min(disponible) from stock where entrega='24 horas');Solución alternativa:select cod, nombre, disponible from stock, articulo where cod=articulo and entrega ='24 horas' and disponible <=all (select disponible from stock where entrega='24 horas');
select numpedido, articulo from linped where importe = (select min(importe) from linped);
select linea, numpedido from linped where cantidad = (select max(cantidad) from linped);Solución alternativa:select linea, numpedido from linped where cantidad >= all (select cantidad from linped);
select distinct linea, nombre from articulo a, linped l where a.cod=l.articulo and importe > (select min(importe) from linped);Solución alternativa:select distinct linea, nombre from articulo a, linped l where a.cod=l.articulo and importe > any (select importe from linped);
select nombre, pvp, marca from articulo a, stock s where a.cod=s.articulo and s.disponible = (select max(disponible) from stock);Solución alternativa:select nombre, pvp, marca from articulo a, stock s where a.cod=s.articulo and s.disponible >=all (select disponible from stock);
select nombre, pvp, marca from articulo a, stock s where a.cod=s.articulo and s.disponible <> (select max(disponible) from stock);Solución alternativa:select nombre, pvp, marca from articulo a, stock s where a.cod=s.articulo and s.disponible < any (select disponible from stock);