나는 꽤 큰 쿼리를 가지고있다. 그것은 다음과 같습니다MyBatis에 MySql 쿼리 결과를 변수로 저장하는 방법
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
.....
)
... 그리고 두 개 더 노동 조합
내가하고 싶은 모든 일부 변수 첫번째로 표 2에서 선택 ID로 시작하고 그 사용 후이 두 개의 내부 쿼리를 조회하는 것입니다을 조합 쿼리에서 쿼리 결과.
나는이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