我的查询错误如下。你能帮我吗?
错误是由不明确的列引起的。我有一个想法,我不确定。
我认为错误是这里的WorkUID列(含糊不清):
<isNotEmpty property="uids">
AND WorkUID IN
<iterate property="uids" open="(" close=")" conjunction=",">
#uids[]#
</iterate>
</isNotEmpty>
这是错误:
Cause: SqlMapClient operation; SQL [];
--- The error occurred while applying a parameter map.
--- Check the getData-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: Ambiguous column name 'WorkUID'.; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the getData-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: Ambiguous column name 'WorkUID'.;
net.extraction.etl.exception.DAOException: Getting work UID by release datetime.
Cause: org.springframework.dao.TransientDataAccessResourceException: SqlMapClient operation; SQL [];
--- The error occurred while applying a parameter map.
--- Check the getData-InlineParameterMap.
以下是查询:
<select id="getData" resultClass="java.lang.Integer" parameterClass="java.util.Map" >
<![CDATA[
SELECT xrn.WorkUID
FROM
(SELECT uow.WorkUID,
ROW_NUMBER() OVER(PARTITION BY wsh.WorkUID ORDER BY wsh.DT DESC) AS rnk
FROM UnitWork uow
INNER JOIN SigHist sh ON sh.SigUID = uow.SigUID
INNER JOIN DataCell d ON d.WorkUID = uow.WorkUID
INNER JOIN WorkStatHist wsh ON (wsh.WorkUID = uow.WorkUID
AND wsh.WorkUID = d.WorkUID
AND 8 =
(SELECT TOP 1 StatusUID
FROM WorkStatHist(NOLOCK)
WHERE WorkUID = uow.workUID
ORDER BY DT DESC))
WHERE (uow.ReleasedDT > #fromDate#)
OR (sh.UpdatedDT > #fromDate#)
AND d.EffectiveTo >= GETDATE() + 1
]]>
<dynamic>
<isNotEmpty property="toDate">
<![CDATA[
AND d.EffectiveTo < #toDate#
]]>
</isNotEmpty>
<isNotEmpty property="uids">
AND WorkUID IN
<iterate property="uids" open="(" close=")" conjunction=",">
#uids[]#
</iterate>
</isNotEmpty>
</dynamic>
<![CDATA[
) xrn
WHERE xrn.rnk=1
]]>
</select>
答案 0 :(得分:1)
我根本不熟悉MyBatis
,所以我不能代表该部分代码,但您的问题似乎与以下部分有关:
<isNotEmpty property="uids">
AND WorkUID IN
<iterate property="uids" open="(" close=")" conjunction=",">
#uids[]#
</iterate>
</isNotEmpty>
特别是AND WorkUID IN
部分。
您的查询中有多个表以WorkUID
作为列,因此它不知道从哪个表中提取它。
看到它被用作每个表的JOIN
约束,我们告诉它查看哪个表并不特别重要。
将其更改为以下内容应该清除该错误:
<isNotEmpty property="uids">
AND uow.WorkUID IN
<iterate property="uids" open="(" close=")" conjunction=",">
#uids[]#
</iterate>
</isNotEmpty>