如何使用子查询过滤两次?

xmq68pz9  于 2021-06-25  发布在  Mysql
关注(0)|答案(2)|浏览(321)

**结束。**此问题需要详细的调试信息。它目前不接受答案。
**想改进这个问题吗?**更新问题,使其成为堆栈溢出的主题。

两年前关门了。
改进这个问题
我试图选择约束相互矛盾的数据。例如,当项目编号不为空时,有些数据集的状态描述为“90-失去机会”。我想过滤它两次,所以首先我得到所有的项目编号为空,然后我可以再次过滤这个查询,得到一个状态为“90失去机会”的表

SELECT ProjectNumber,
       PName
FROM
(
    SELECT DISTINCT
           T0.project_number_ext AS ProjectNumber,
           T0.project_key AS PKey,
           T0.sproject_number AS sPNumber,
           T0.project_number AS PNumber,
           T0.schedule_finish AS SFinish,
           T0.status_desc AS SDesc,
           T0.Project_name AS PName
    FROM trimergo.rpt_getProjectPOC T0
    WHERE T0.sproject_number IS NULL
)
GROUP BY ProjectNumber,
         PName;
p5cysglq

p5cysglq1#

这段代码工作,我试图选择数据的约束是矛盾的。例如,当项目编号不为空时,有些数据集的状态描述为“90-失去机会”。我想过滤它两次,所以首先我得到所有空的数据集,然后我过滤那个查询来关闭我需要的数据集

SELECT
T1.ProjectNumber , T1.PName, T1.SDesc

FROM
( 

SELECT DISTINCT 
 T0.project_number_ext as ProjectNumber
,T0.project_key as PKey
,T0.sproject_number as sPNumber 
,T0.project_number as PNumber
,T0.schedule_finish as SFinish
,T0.status_desc as SDesc
,T0.Project_name as PName

From trimergo.rpt_getProjectPOC T0

WHERE T0.sproject_number IS NULL ) AS T1

Where T1.SDesc LIKE '10 - In Proposal%'
OR T1.SDesc like '90-Lost Opportunity%'

Group by ProjectNumber, PName, SDesc
bttbmeg0

bttbmeg02#

我想你只需要这个。不需要子查询。

SELECT 
        DISTINCT 
         T0.project_number_ext as ProjectNumber
        ,T0.status_desc as SDesc
        ,T0.Project_name as PName
    From trimergo.rpt_getProjectPOC T0
    WHERE T0.sproject_number IS NULL AND 
    ( T1.SDesc LIKE '10 - In Proposal%' OR T1.SDesc like '90-Lost Opportunity%' )

相关问题