4

我正在处理一些 sql 查询以从表中获取一些数据;我对相同的数据进行了 2 次查询,但都给出了另一个结果。2个查询是:

SELECT Samples.Sample,
       data_overview.Sample_Name,
       data_overview.Sample_Group,
       data_overview.NorTum,
       data_overview.Sample_Plate,
       data_overview.Sentrix_ID,
       data_overview.Sentrix_Position,
       data_overview.HybNR,
       data_overview.Pool_ID
FROM tissue INNER JOIN (
                            ( patient INNER JOIN data_overview
                                ON patient.Sample = data_overview.Sample)
                        INNER JOIN Samples ON
                          (data_overview.Sample_id = Samples.Sample_id) AND
                          (patient.Sample = Samples.Sample)
                        ) ON
                        (tissue.Sample_Name = data_overview.Sample_Name)  AND 
                        (tissue.Sample_Name = patient.Sample_Name)
     WHERE data_overview.Sentrix_ID= 1416198
          OR data_overview.Pool_ID='GS0005701-OPA'
          OR data_overview.Pool_ID='GS0005702-OPA'
          OR data_overview.Pool_ID='GS0005703-OPA'
          OR data_overview.Pool_ID='GS0005704-OPA'
          OR data_overview.Sentrix_ID= 1280307
     ORDER BY Samples.Sample;")

另一个是

SELECT Samples.Sample,
       data_overview.Sample_Name,
       data_overview.Sample_Group,
       data_overview.NorTum,
       data_overview.Sample_Plate,
       data_overview.Sentrix_ID,
       data_overview.Sentrix_Position,
       data_overview.HybNR,
       data_overview.Pool_ID
FROM tissue INNER JOIN 
                      (
                         (patient INNER JOIN data_overview 
                               ON patient.Sample = data_overview.Sample)
                          INNER JOIN Samples ON
                              (data_overview.Sample_id = Samples.Sample_id)
                              AND (patient.Sample = Samples.Sample)) ON
                              (tissue.Sample_Name = data_overview.Sample_Name)
                          AND (tissue.Sample_Name = patient.Sample_Name)
          WHERE ((
                    (data_overview.Sentrix_ID)=1280307)
                AND (
                     (data_overview.Pool_ID)="GS0005701-OPA"
                     OR (data_overview.Pool_ID)="GS0005702-OPA"
                     OR (data_overview.Pool_ID)="GS0005703-OPA" 
                     OR (data_overview.Pool_ID)="GS0005704-OPA"))
                     OR (((data_overview.Sentrix_ID)=1416198))
ORDER BY data_overview.Sample;

顶部的那个工作得很好,但它仍然不会过滤 sentrix_ID。第二个 1 是使用 Access 创建的,但是当我尝试在 R 中运行此查询时,它给出了意外的符号错误。因此,如果有人知道如何使用给定的参数创建过滤 POOL_ID 和 Sentrix_id 的查询,请提前感谢

4

2 回答 2

1

也许你的意思是:

 ...
 WHERE data_overview.Sentrix_ID IN (1280307,1416198 )
   AND data_overview.Pool_ID IN ("GS0005701-OPA", "GS0005702-OPA", "GS0005703-OPA" ,"GS0005704-OPA")
   ;                  
于 2012-06-26T15:43:57.507 回答
1

是否将 where 子句制作成这样:

 WHERE Sentrix_ID = 1280307 AND (Pool_ID = 'VAL1' OR Pool_ID = 'VAL2' OR Pool_ID = 'VAL3')

即确保“或”组件周围有括号?

于 2012-06-26T13:16:11.360 回答