跨多个变量Access Query显示结果

时间:2015-02-24 15:48:26

标签: ms-access

我有一系列5个变量(来自同一张表)。我想查询一个查询,向我显示中至少有一个这些变量值的参与者。即,如果所有5个变量都是空白,则不显示该参与者。我怎么能这样做呢?

SELECT [Patient Information].MRN, [Patient Information].[MRI_Results(1)], [Patient Information].[MRI_Results(2)], [Patient Information].[Blood_Results(Base)], [Patient Information].[Blood_Results(FU1)], [Patient Information].[Blood_Results(FU2)], [Patient Information].[Blood_Results(FU3)]
FROM [Patient Information]
ORDER BY [Patient Information].[MRI_Results(1)] DESC , [Patient Information].[MRI_Results(2)] DESC , [Patient Information].[Blood_Results(Base)] DESC , [Patient Information].[Blood_Results(FU1)] DESC , [Patient Information].[Blood_Results(FU2)] DESC , [Patient Information].[Blood_Results(FU3)] DESC;

1 个答案:

答案 0 :(得分:2)

一个简单的“WHERE”子句可以解决问题。您希望使用OR运算符,因为只要有一个值,您希望保留记录。

根据您的值,您可能需要更改语法(即“Not IsNull()”而不是“Is Not Null”),因此这可能需要进行一些小的调整,但应该让您朝着正确的方向前进。

SELECT [Patient Information].MRN, [Patient Information].[MRI_Results(1)],
       [Patient Information].[MRI_Results(2)], 
       [Patient Information].[Blood_Results(Base)], 
       [Patient Information].[Blood_Results(FU1)], 
       [Patient Information].[Blood_Results(FU2)], 
       [Patient Information].[Blood_Results(FU3)]
FROM [Patient Information]
WHERE [Patient Information].MRN IS NOT NULL
  OR [Patient Information].[MRI_Results(1)] IS NOT NULL
  OR [Patient Information].[MRI_Results(2)] IS NOT NULL
  OR [Patient Information].[Blood_Results(Base)] IS NOT NULL
  OR [Patient Information].[Blood_Results(FU1)] IS NOT NULL
  OR [Patient Information].[Blood_Results(FU2)] IS NOT NULL
  OR [Patient Information].[Blood_Results(FU3)] IS NOT NULL

ORDER BY [Patient Information].[MRI_Results(1)] DESC , 
         [Patient Information].[MRI_Results(2)] DESC , 
         [Patient Information].[Blood_Results(Base)] DESC , 
         [Patient Information].[Blood_Results(FU1)] DESC , 
         [Patient Information].[Blood_Results(FU2)] DESC , 
         [Patient Information].[Blood_Results(FU3)] DESC;