我的家庭作业的一部分要求处理一个执行随机删除,更新和插入的sql脚本,然后我们的任务是列出这些DML语句。香港专业教育学院试图一个答案,并一直试图使其工作,但我一直得到错误的结果。这是我的每个DML语句的代码
删除
SELECT *
FROM ag715
WHERE ORDER_ID NOT IN(SELECT ORDER_ID
FROM ORDER_DETAIL);
更新
SELECT TA.*, CA.*
FROM ag715 TA JOIN ORDER_DETAIL CA
ON TA.ORDER_ID = CA.ORDER_ID
WHERE TA.PRODUCT_NAME = CA.PRODCUT_NAME AND (
TA.UNIT_PRICE <> CA.UNIT.PRICE ON
TA.QUANTITY == CA.QUANTITY OR
TA.DISCOUNT <> CA.DISCOUNT);
插入
SELECT *
FROM ORDER_DETAIL
WHERE ORDER_ID,PRODUCT_NAMEN NOT IN(SELECT ORDER_ID, PRODUCT_NAME FROM ag715);
解释表:ORDER_DETAIL是随机DML语句在其中影响的表的名称。表ag715是原始表的备份。因此,我得出的结论是,要显示上述DML语句,我们必须将两个表进行比较。每条对账单仅应显示3条受影响的行,而我每行应显示300-350条左右。
谢谢大家
在这里编辑是执行DDL语句的脚本
CREATE TABLE order_detail AS (SELECT * FROM ORDER_DETAIL);
DELETE FROM order_detail
WHERE order_id = 267;
INSERT INTO order_detail VALUES(249,'Singaporean Hokkien Fried Mee', 0.0, 0.0, 0.0);
DELETE FROM ORDER_DETAIL;
INSERT INTO ORDER_DETAIL( SELECT * FROM order_detail);
INSERT INTO ORDER_DETAIL VALUES(251, 'Manjimup Dried Apples', 0.0, 0.0, 0.0);
INSERT INTO ORDER_DETAIL VALUES(250, 'Singaporean Hokkien Fried Mee', 0.0, 0.0, 0.0);
UPDATE ORDER_DETAIL
SET unit_price = unit_price + 1, quantity = quantity + 1
WHERE order_id = 248;
DELETE FROM order_detail;
DROP TABLE order_detail;
COMMIT;