c# - 如何从另一个表中的另一列等于我的参数值的表中选择数据?

标签 c# sql-server

我是初学者,我想: - 当 total quant = 0 且第二个表中的 status 字段等于 process 时,从下表中获取 recivedID table 1 - stockTBL

table 2 - recivedTBL

这意味着当此订单中的所有产品 = 0 且订单状态 = 处理时 我想返回 recivedID

这是我的代码:

SELECT s.recivedID FROM stockTBL s
JOIN recivedTBL r ON r.recivedID = s.recivedID
WHERE r.status = @STATUS 
GROUP BY s.recivedID 
HAVING (SUM(s.quant) = 0)

最佳答案

因此,您想要选择所有已接收的 TBL 记录,这些记录没有关联的库存 TBL。

SELECT s.recivedID, SUM(s.quant) 
  FROM stockTBL s
  JOIN recivedTBL r ON r.recivedID = s.recivedID
 WHERE r.status = @STATUS 
 GROUP BY s.recivedID 
HAVING (SUM(s.quant) = 0) -- sum stockTBL

关于c# - 如何从另一个表中的另一列等于我的参数值的表中选择数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41491526/

相关文章:

C# NET4.0 任务保持引用

sql-server - 在 sys.database_files 中找不到数据库 'mydatabase' 的文件 'mydatabase'。该文件不存在,或已被删除

sql-server - 升级到 Python 3.6 和 SQL Server 2016 后出现 Pymssql 错误 20017

c# - 如何在 C# 中将数组添加到 SQL 行?

sql-server - 使用 DtExecUI.exe 时未填充包源路径

c# - 最佳模拟库

c# - 有延迟的链接任务

c# - 使用 PLINQ Extensions 时,线程标识是否被转移?

sql - 连接字符串不起作用,无法读取文件位置

c# - WCF : How cand you add multiple MessageBodyMember to a MessageContract if one is Stream