SELECT extendedprice,orderkey,tax,discount FROM lineitem WHERE orderkey = 18;
DELIMITER $$
CREATE PROCEDURE proc2()
BEGIN
UPDATE lineitem SET extendedprice = extendedprice * discount * (1+tax) WHERE orderkey = 18;
END;
$$
DELIMITER ;
CALL proc2();
SELECT extendedprice,orderkey,tax,discount FROM lineitem WHERE orderkey = 18;
定义一个存储过程proc3,更新某个顾客的所有订单的(含税折扣价)总价,执行这个存储过程。
SELECT extendedprice,orderkey,tax,discount FROM lineitem WHERE orderkey IN (SELECT orderkey FROM orders WHERE custkey = 320728);
DELIMITER $$
CREATE PROCEDURE proc3()
BEGIN
UPDATE lineitem SET extendedprice = extendedprice * discount * (1+tax) WHERE orderkey IN (SELECT orderkey FROM orders WHERE custkey = 320728);
END;
$$
DELIMITER ;
CALL proc3();
SELECT extendedprice,orderkey,tax,discount FROM lineitem WHERE orderkey IN (SELECT orderkey FROM orders WHERE custkey = 320728);
SELECT extendedprice,orderkey,tax,discount FROM lineitem WHERE orderkey IN (SELECT orderkey FROM orders WHERE custkey = 518445);
DELIMITER $$
CREATE PROCEDURE proc4()
BEGIN
DECLARE sum_price numeric(10,2);
UPDATE lineitem SET extendedprice = extendedprice * discount * (1+tax) WHERE orderkey IN (SELECT orderkey FROM orders WHERE custkey = 320728);
SELECT SUM(lineitem.extendedprice) INTO sum_price FROM lineitem,orders WHERE orders.custkey = 518445 && lineitem.orderkey=orders.orderkey GROUP BY orders.custkey;
UPDATE orders SET totalprice = sum_price;
END;
$$
DELIMITER ;
CALL proc3();
SELECT extendedprice,orderkey,tax,discount FROM lineitem WHERE orderkey IN (SELECT orderkey FROM orders WHERE custkey = 320728);