首页 > 解决方案 > 将数据从一个表传输到另一个表

问题描述

我需要有关我的 sql 代码的帮助,有没有办法将数据从第一个 SELECT 语句的“AS subtotal”传输到第二个 SELECT 语句的“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


标签: sql

解决方案


您需要将其写入单个 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

推荐阅读