sql - 将数据从一个表传输到另一个表
问题描述
我需要有关我的 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
解决方案
您需要将其写入单个 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
推荐阅读
- formal-languages - 有没有办法为这种语言创建类型 3 语法?
- javascript - 如何增加amcharts中的雷达半径
- antlr - 无法编写词法分析器来解析这个
- css - tsdx - 导入 .css - 错误 - PostCSS 插件 postcss-modules 需要 PostCSS 8
- python - 如何在 Flask 函数中将击键传递给子进程?
- c# - 选择歌曲后 Mp3 播放器滞后 (c#)
- python - 向我的数组追加或插入随机元素
- c++ - 运行时错误:以下代码的运行时错误分段错误 (SIGSEGV)
- c# - Pulumi 本地工作区配置值,这些是否适用于 Azure 部署?
- python - 如何使用 environment.yaml 文件在 Python 中创建虚拟环境?