SELECT a.ID ,
a.Sub_Project_Name ,
a.Sub_Project_Type
FROM TB_KYSubProject a
WHERE a.ID NOT IN (
SELECT DISTINCT c.SubprojectID
FROM TB_KYGrogramme c
WHERE ISNULL(c.Belong_Programme, \'\') <> \'\'
AND c.Belong_Programme IN ( SELECT ConfigValue
FROM PB_Config
WHERE ConfigKey = \'子项目共有所属方案\' ) )
但是查询TB_KYGrogramme和TB_KYSubProject都有数据,TB_KYSubProject比TB_KYGrogramme的数据还多,不应该没数据
SELECT DISTINCT c.SubprojectID
FROM TB_KYGrogramme c
WHERE ISNULL(c.Belong_Programme, \'\') <> \'\'
AND c.Belong_Programme IN ( SELECT ConfigValue
FROM PB_Config
WHERE ConfigKey = \'子项目共有所属方案\' )
SELECT DISTINCT a.ID
FROM TB_KYSubProject a
SELECT DISTINCT c.SubprojectID
FROM TB_KYGrogramme c
WHERE ISNULL(c.Belong_Programme, \'\') <> \'\'
AND c.Belong_Programme IN ( SELECT c.ConfigValue
FROM PB_Config c
WHERE c.ConfigKey = \'子项目共有所属方案\' )
AND c.SubprojectID IS NULL
SELECT 1 AS id ,
1 AS subprojectid
UNION
SELECT 2 AS id ,
2 AS subprojectid
UNION
SELECT 3 AS id ,
3 AS subprojectid
UNION
SELECT 4 AS id ,
NULL AS subprojectid
SELECT *
FROM ( SELECT 1 AS id ,
1 AS subprojectid
UNION
SELECT 2 AS id ,
2 AS subprojectid
UNION
SELECT 3 AS id ,
3 AS subprojectid
UNION
SELECT 4 AS id ,
NULL AS subprojectid
) vv
WHERE subprojectid NOT IN ( 1, NULL )
SELECT *
FROM ( SELECT 1 AS id ,
1 AS subprojectid
UNION
SELECT 2 AS id ,
2 AS subprojectid
UNION
SELECT 3 AS id ,
3 AS subprojectid
UNION
SELECT 4 AS id ,
NULL AS subprojectid
) vv
WHERE subprojectid <> 1
AND subprojectid <> NULL
知道问题原因,对sql语句修改,把SubprojectID是NULL的数据排查
SELECT a.ID ,
a.Sub_Project_Name ,
a.Sub_Project_Type
FROM TB_KYSubProject a
WHERE a.ID NOT IN (
SELECT DISTINCT c.SubprojectID
FROM TB_KYGrogramme c
WHERE ISNULL(c.Belong_Programme, \'\') <> \'\'
AND c.Belong_Programme IN ( SELECT ConfigValue
FROM PB_Config
WHERE ConfigKey = \'子项目共有所属方案\' ) AND c.SubprojectID IS NOT NULL)
开发中遇到该问题记录下