IN子句中的SQL多列转换为JPA [英] SQL Multiple Columns in IN clause to convert to JPA

查看:294
本文介绍了IN子句中的SQL多列转换为JPA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 IN 子句中的多列转换/翻译下面的查询为 JPA

I want to convert/translate the below query with multiple columns in IN clause to JPA.

查询

Query:

SELECT city FROM user WHERE (firstName, lastName) IN (('a', 'b'), ('c', 'd'));


推荐答案

我不知道JPA是什么谷歌它,我的意思是,我不熟悉它);但是:如果有任何希望处理SQL查询,并且唯一的问题是转换元组上的条件,那么重新编写这样的查询:

I don't know what JPA is (I can Google it; what I mean is that I am not familiar with it); but: if there is any hope to handle a SQL query, and the only issue is translating a condition on tuples, then rewrite the query like so:

select city 
from   user
where  firstname = 'a' and lastname = 'b'
   or  firstname = 'c' and lastname = 'd'
;

这就是查询引擎对原始查询执行的操作。你可以看看一个解释计划来说服你自己。

This is what the query engine will do with your original query regardless; you can look at an EXPLAIN PLAN to convince yourself of this.

有些人喜欢在每对连接条件;我不会,除了我会用2 * 3 + 4 * 6的圆括号,但如果你觉得他们增加了清晰度,你可以添加它们。

Some people like to put parentheses around each pair of AND-connected conditions; I don't, any more than I would use parentheses for 2 * 3 + 4 * 6, but if you feel they add clarity, by all means you can add them.

这篇关于IN子句中的SQL多列转换为JPA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆