[英]Querying for multiple values in multiple columns
How would I search multiple (in this example, say 2) columns for an array of values?我将如何搜索多个(在此示例中为 2 个)列以查找值数组?
For example, here is my table Documents
:例如,这是我的表Documents
:
1. DocNumber (varchar)
2. CompanyCode (varchar)
3. Data1 (varchar)
4. Data2 (varchar)
5. Data3 (varchar)
DocNumber and CompanyCode form the composite primary key of this table. DocNumber 和 CompanyCode 构成了该表的复合主键。 Say I have a set of values which I want to search in the database such as:假设我有一组要在数据库中搜索的值,例如:
DocNumber文件编号 | CompanyCode公司代码 |
---|---|
1001 1001 | 101 101 |
1002 1002 | 102 102 |
1004 1004 | 103 103 |
How would I find these unique combinations in the table with one query?我如何通过一个查询在表中找到这些独特的组合?
I could use in
:我可以in
:
select *
from Documents
where DocNumber in :docNumbers and CompanyCode in :companyCodes
But that would also return records with DocNumber 1001 and CompanyCode 102 (all combinations of the 2 lists).但这也会返回 DocNumber 1001 和 CompanyCode 102 的记录(这两个列表的所有组合)。 I want to avoid that.我想避免这种情况。
I am using HANA DB (through a Spring Boot application).我正在使用 HANA DB(通过 Spring 启动应用程序)。
Sample table data:示例表数据:
table data表数据
Expected response:预期响应:
expected response预期反应
Response I get:我得到的回应:
current response当前响应
The IN
predicate also works with tuples. IN
谓词也适用于元组。 Please find a minimal example:请找一个最小的例子:
SELECT *
FROM
(
SELECT 'A1' AS DOCNUMBER, 'A2' AS COMPANYCODE FROM DUMMY
)
WHERE (DOCNUMBER, COMPANYCODE) IN (('A1', 'A2'),('B1', 'B2'))
Further details and examples can be found in the documentation .可以在文档中找到更多详细信息和示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.