sql中具有新创建字段的条件

时间:2018-06-04 15:25:38

标签: sql ms-access

我有以下查询,为什么我不能让我的where子句工作?该值确实存在于表中。

 Select B.*, B.[RF attribute1] & "|" & B.[RF attribute2] & "|" & B.[RF attribute3] & "|" & B.[RF attribute4] as new_field 
FROM [Black$] as B 
where new_field = "Stack|over||flow"

错误消息为No value given for one or more required paramters

修改,实际数据:

+---------------+---------------+---------------+---------------+
| RF attribute1 | RF attribute2 | RF attribute3 | RF attribute4 |
+---------------+---------------+---------------+---------------+
| BONDZERO      | AUD           |               | MID           |
| BONDZERO      | AUD           |               | MID           |
| SWAPZERO      | AUD           |               | MID           |
| SWAPZERO      | AUD           |               | MID           |

将创建一个新字段,如下所示:

+-------------------+
|     new_field     |
+-------------------+
| BONDZERO|AUD||MID |
| BONDZERO|AUD||MID |
| SWAPZERO|AUD||MID |
| SWAPZERO|AUD||MID |
+-------------------+

现在我正在尝试使用where子句BONDZERO|AUD||MID,因此它只返回前两行。

2 个答案:

答案 0 :(得分:1)

Access认为您尝试将new_field作为参数传递。

您需要详细说明WHERE条款:

Select B.*, B.[RF attribute1] & "|" 
          & B.[RF attribute2] & "|" 
          & B.[RF attribute3] & "|" 
          & B.[RF attribute4] as new_field 
FROM [Black$] as B 
where       B.[RF attribute1] & "|" 
          & B.[RF attribute2] & "|" 
          & B.[RF attribute3] & "|" 
          & B.[RF attribute4] = "Stack|over||flow"

答案 1 :(得分:1)

使用子查询:

select b.*
from (Select B.*, B.[RF attribute1] & "|" & B.[RF attribute2] & "|" & B.[RF attribute3] & "|" & B.[RF attribute4] as new_field 
      from [Black$] as B 
     ) as b
where new_field = "Stack|over||flow";