El ejemplo me sale en un libro de MySQL para ilustrar los procedimientos almacenados, pero ya se especifica que este mismo ejemplo se puede hacer en una sola pequeña consulta.
Lo he intentado de varias formas y no me sale. Alguna ayuda?
Algunos intentos fallidos que he hecho:
Código:
select orderid from orders where (select max(amount) from orders);
Código:
select orderid, amount from orders where amount >= all (select amount from orders);
Lo gracioso es que ahora sólo me sale de la manera más larga, con el procedimiento almacenado. Os lo dejo aquí también para quien esté interesado en saber cómo es:
Código:
# Cambiar delimitador de punto y coma a doble barra: delimiter // create procedure mayor_pedido (out id_mayor_pedido int) begin declare id_actual; declare total_actual float; declare ultimo_total_mayor float default 0.0; declare ultimo_id_mayor int; declare hecho int default 0; declare continue handler for not found set hecho = 1; declare fila_actual cursor for select orderid, amount from orders; open fila_actual; repeat fetch fila_actual into id_actual, total_actual; if not hecho then if total_actual > ultimo_total_mayor then set ultimo_total_mayor = total_actual; set ultimo_id_mayor = id_actual; end if; end if; until hecho end repeat; close fila_actual; set id_mayor_pedido = ultimo_id_mayor; end # Ejecutar procedimiento con la doble barra: // #devolver función de ejecución de comandos al punto y coma: delimiter ;