选择sql中的产品数量 [英] Selecting count of products in sql
问题描述
HI
我正在尝试从桌子上计算产品数量。
我目前有一个名为listStages的视图,它是下表的联合声明(接收,浸泡,测试,修复,软件,发送)
括号中的每个表都有passfail.pass = 1 fail = 0
ListStages显示每个产品以及它是否在阶段通过或失败。
我想知道如何能够选择每个表上只有pass(1)的产品,如果它有失败,那么它不应该显示在我的记录中查询
HI
I am trying to do a count of productserials from a table.
I currently have a view called listStages which is a union statement of the following tables(receive,soak,test,repair,software, dispatch)
each table in the brackets has a passfail.pass = 1 fail = 0
ListStages shows each product and if it was passed or failed at a stage.
I would like to know how would i be able to select the products which only have a pass(1) on each table and if it has a fail then it should not show in my records which are returned by the query
推荐答案
最简单的方法是在所有表的where条件中使用pass = 1
或使用公用表表达式,在其中写入union查询并在输出处使用where条件
Hi,
Simplest way is to use pass = 1 in where condition for all tables
or use a common table expression , write your union query inside it and use where condition at output
我不确定你想要做什么,但根据你的评论:
I''m not sure wjat you want to do, but based on your comment:
Rceive pass--> soak fail--> repair Pass--> soak pass--> test pass--> dispatch
now i need to select only the products that follow the 1st process. if i select * from ListStage where passfail = 1 then it will return the value of the product which had a repair. and i want it to show only the products which do not have a repair
i建议你这样做:
i recommend you to do something like this:
SELECT LS.*
FROM listStages AS LS LEFT JOIN Rceive AS RC ON LC.ProductID = RC.ProductID
WHERE RC.Pass=1
或
or
SELECT *
FROM listStages
WHERE ProductID IN (
SELECT ProductID
FROM Rceive
WHERE Pass=1)
根据我的理解......你想要这个....
As per my understanding ... you want this ....
Select stage,product,SUM(CAST(passfail AS numeric)) from listStages
GROUP BY stage,product
Having SUM(CAST(passfail AS numeric)) = COUNT(1)
这篇关于选择sql中的产品数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!