简体   繁体   English

通过比较同一表中的互斥值,从表中选择所有数据

[英]Select all data from table by comparing mutually exclusive values in the same table

I have a Microsoft Access table as show below, Where Item 1 and Item 2 are mutually exclusive. 我有一个Microsoft Access表,如下所示,其中项1项2是互斥的。 在此处输入图片说明

I need a query to generate the following result 我需要查询以生成以下结果 在此处输入图片说明

  1. Always retrieves all the entries of the table 始终检索表的所有条目
  2. If both Item 1 and Item 2 is present (manual editing of database is possible) only values of Item 2 will be returned in the result. 如果同时存在项目1项目2 (可以手动编辑数据库),则结果中将仅返回项目2的值。
  3. Original table should not be altered 原始表格不得更改

What should I do? 我该怎么办?

You should use IIF(Condition, ValueIfTrue, ValueIfFalse) statement: 您应该使用IIF(Condition, ValueIfTrue, ValueIfFalse)语句:

SELECT Id, IIF([Item 1] IS NOT NULL AND [Item 2] IS NOT NULL, NULL, [Item 1]) AS [Item 1], [Item 2]

FROM TableName

Office Support IIF Function Office支持IIF功能

据我所知,最好将case语句与排名函数一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM