简体   繁体   English

如何选择所有产品数量为零的订单 ID?

[英]how to select order ID where all products quantity equal to zero?

I have the a table like below我有一张如下表

在此处输入图片说明

I want to get recivedID that have quant=0我想获得quant=0 recivedID

In this table we have tow recivedID them products quantity equal to zero how to select recivedID which all it products quantity equal to zero i ho you understand what i mean , and i am very sorry for my bad english skill Thank you在这个表中,我们有两个 recivedID 他们的产品数量等于零如何选择所有产品数量为零的 recivedID 我你明白我的意思,我很抱歉我的英语水平不好谢谢你

SELECT DISTINCT
        rd.recivedID FROM recivedDetailsTBL rd 
JOIN stockTBL s ON s.recivedID = rd.recivedID 
WHERE  
    (SELECT COUNT(*) FROM recivedDetailsTBL rd WHERE rd.recivedID =  @recivedID ) --3
        =
    (SELECT COUNT(*) FROM stockTBL s WHERE s.quant =0 AND s.recivedID = @recivedID  )--3

Presumably you're talking about something similar to this in SQL Format:据推测,您正在谈论类似于 SQL 格式的内容:

SELECT recivedID FROM stock WHERE quant = '0'

Such a query would select the recivedID from the Stock Table where the quant of the item is 0.这样的查询将从 Stock 表中选择 recivedID,其中项目的 quant 为 0。

OK,好的,

So where respondents are getting confused is your explanation...因此,受访者感到困惑的地方是您的解释......

From your explanation, you can have many prodID in one recivedID从你的解释,你可以有很多prodID在一个recivedID

From what you have been saying, you only want the recivedID where the sum of the quant is 0.从你一直在说什么,你只希望recivedID其中的总和quant为0。

So you need to use the HAVING clause:所以你需要使用HAVING子句:

SELECT
recivedID
FROM recivedDetailsTBL
GROUP BY recivedID
HAVING SUM(quant) = 0

First:-第一的:-

use the next code:-使用下一个代码:-

Select  recivedID
From  TableName
GROUP BY recivedID
HAVING SUM(quant) = 0

Second:-第二:-

Lean SQL Statements Concepts, there are thousands of resourses, use this as an example: Lean SQL Statements Concepts,资源上千,以这个为例:

SQL Tutorial SQL 教程

    SELECT recivedID FROM stockTBL GROUP BY recivedID HAVING (SUM(quant) = 0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM