我有很大的查詢。它看起來像這樣:如何將MySql查詢結果存儲在MyBatis變量中
select * from
(
select [custom columns]
from table
where id in
(
select id
from table2
where pr_id in
(
select id
from table3
where id = #{id}
) and ac_id != #{acId}
) and [some_column1] like #{pattern}
union
select [custom columns2]
from table
where id in
(
select id
from table2
where pr_id in
(
select id
from table3
where id = #{id}
) and ac_id != #{acId}
) and [some_column2] like #{pattern}
union
.....
)
...和兩個工會
所有我想要做的就是查詢與選擇ID開始從表2爲一些變量第一和使用後這兩個內查詢在聯合查詢中查詢結果。
我想是這樣的
SET @var1 = (
select id
from table2
where pr_id in
(
select id
from table3
where id = #{id}
) and ac_id != #{acId}
)
select * from
(
select [custom columns]
from table
where id in
(select @var1)
and [some_column1] like #{pattern}
union
....
)
但MyBatis的一個錯誤提供了我。有辦法做我需要的嗎?
錯誤是以下幾點:
Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select * from
(
select firstname, lastname, organization, email, null ' at line 11
選擇名字,姓氏,組織,電子郵件,空「的第11行是[自定義列]
完全[自定義列]是這樣的:
select firstname, lastname, organization, email, null 'applicationId', null 'applicationName', (locate(_ascii #{value}, convert(email using ascii)) - 1) 'index', length(#{value}) 'length', 'EMAIL' as 'type'
什麼是錯誤? –
@GordonLinoff我更新了我的問題。 – Dmitriy