![](/img/trans.png)
[英]Stored procedure for altering data after transferring it from one table to another?
[英]Transferring Data from one table to another
我需要有关我的 sql 代码的帮助,有没有办法让我将数据从第一个 SELECT 语句的“AS subtotal”传输到第二个 Z63225F19FCCB18E3C709F1FA1EZBC1 语句的“receipt.totalAmount”。 sql 有点新 我试图在网上查找它,但我没有看到任何解决方案。 我无法声明从第一个 SELECT 语句到第二个 SELECT 语句的小计。 是否可以将所有小计汇总到总列?
SELECT productServices.productId, productServices.proPrice, orders.orderId, orders.quantity, productServices.proPrice*orders.quantity AS subtotal , orders.dateOrdered
FROM productServices
JOIN orders
ON productServices.productId=orders.productId
SELECT receipt.receiptNo, receipt.customerId, receipt.orderId, receipt.employeeId, receipt.totalAmount, receipt.paymentMethod, receipt.dateOfPurchase
FROM receipt
JOIN customerInfo ON customerInfo.customerId=receipt.customerId
JOIN employeeInfo ON employeeInfo.employeeId=receipt.employeeId
JOIN orders ON orders.orderId=receipt.orderId
您需要将其写入单个 select 语句。 像这样的东西。 或者使用内部查询来获得你需要的东西。
SELECT receipt.receiptNo, receipt.customerId, receipt.orderId, receipt.employeeId, receipt.totalAmount, receipt.paymentMethod, receipt.dateOfPurchase,
productServices.productId, productServices.proPrice, orders.orderId, orders.quantity, productServices.proPrice*orders.quantity AS subtotal , orders.dateOrdered
FROM receipt
JOIN customerInfo ON customerInfo.customerId=receipt.customerId
JOIN employeeInfo ON employeeInfo.employeeId=receipt.employeeId
JOIN orders ON orders.orderId=receipt.orderId
JOIN productServices on productServices.productid = orders.productid
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.