sql-server - 获取一个表中的数据并使用它在 SQL SERVER 中的另一个表中获取更多数据?
问题描述
我在 SQL SERVER 中有两个表,它们是 1) tblBuyerCodes
2) tblStatistics
。
我想在 SQL Server 中实现的是在第一个表中获取一个buyer code
,在该买方代码的第二个表中获取统计信息并在第三个表中插入详细信息,我们称之为tblResults
。如何在 SQL Server 存储过程中实现这一点?
眼镜:
tblBuyerCodes have columns (id, buyercode).
tblStatistics have columns (id,buyercode,goodsbought,total).
tblResults have columns (id, buyercode,goodsbought,total,date).
我想要实现的只是在 tblStatistics 中获取结果,然后根据从 tblBUyerCodes 表中获取的买家代码将它们发布到 tblResults 中
For example results will be:
row 1: dm6 23 45689
row 2: dm8 45 3456
dm6
并dm8
成为买方代码
解决方案
基于我们所拥有的有限细节,为什么不只是?
INSERT INTO tblResult (id, buyercode,goodsbought,total,date)
SELECT id,
buyercode,
goodsbought,
total,
{SomeDateValue} --Maybe GETDATE()?
FROM tblStatistics;
推荐阅读
- elasticsearch - ElasticSearch 覆盖从文本到对象的映射
- django - Django - 获取每个关系中的最新对象
- gtag.js - 在 ajax 调用上添加谷歌分析代码
- google-cloud-platform - 如何创建具有多个项目权限的 GCP 服务帐户?
- internet-explorer - 滚动 x 时 ie 11 中的不稳定运动
- qt - Qml 恢复最小化窗口
- c# - 如何多次打开带有 logfil 的程序?(C#)
- python - 在python中解压缩每个文件夹和子文件夹中的所有.bz2文件
- c# - 是否可以分配列表
到 EditorGUILayout.TextField()? - php - 如何在jquery中选择多个复选框时只显示一次消息或数据?