0

我有以下数据库可以在 Android 3.0 平板电脑应用程序中使用它。

在此处输入图像描述
我想选择它不在的每个缺陷EReportDefect。如您所见EReportDefect.defectId ,可能为 null

此选择返回 0 行。但也有一些没有摆在EReportDefect桌面上的缺陷。

SELECT 
  Defect.defectId,
  Defect.description
FROM 
  Defect 
WHERE 
   qapId = ? AND
   defectId NOT IN 
     (SELECT defectId FROM EReportDefect WHERE eReportId = ?);

我究竟做错了什么?

4

3 回答 3

3

defectID您可以使用LEFT JOIN,在列上加入两个表

SELECT  a.*
FROM    Defect a
        LEFT JOIN EReportDefect b
            ON a.defectID = b.defectID
WHERE   b.defectID IS NULL 

b.defectIDNULL如果在 上没有匹配项,则将具有值a.defectID

更新 1

SELECT a.*
FROM    Defect a
        LEFT JOIN EReportDefect b
            ON a.defectID = b.defectID
WHERE  b.defectID IS NULL AND
        a.qapID = ? 
       -- AND b.ReportID = ?
于 2012-10-04T15:37:51.537 回答
0

这就是我制作作品的方式:

SELECT
   Defect.defectId,
   Defect.description
FROM
   Defect
WHERE
   qapId = ? AND
   defectId NOT IN 
     (SELECT
        defectId
      FROM
        EReportDefect
      WHERE eReportId = ? AND defectId IS NOT NULL);
于 2012-10-04T16:09:21.980 回答
-1

也许我遗漏了一些东西,但对我来说,如果你删除“qapId = ?AND”和“WHERE eReportId =?” 它应该只返回 EReportDefect 表中没有条目的结果

SELECT 
  Defect.defectId,
  Defect.description
FROM 
  Defect 
WHERE 
   defectId NOT IN 
     (SELECT defectId FROM EReportDefect);
于 2012-10-04T15:48:10.860 回答