我需要帮助我的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
1条答案
按热度按时间mdfafbf11#
您需要将其写入一个select语句中。像这样的。或者使用内部查询来获取所需的内容。