0

我在 myBatis 映射器中编写了一个简单的选择:

<select id="listAllOrders" parameterType="java.util.HashMap" resultMap="commonMaps.detailedOrderResultMap">

    select

    <include refid="commonSql.fragmentOrderFields" />,
    <include refid="commonSql.fragmentSummaryPriceInfoFields" />

    from graorder order 
          left outer join grasummarypriceinfo summarypriceinfo on order.totalPrice_id = summarypriceinfo.id

    <if test="userGroupId != null">
        where order.userGroupId = #{userGroupId}
    </if>

    order by order_lastUpdated desc

    <if test="limit != null">
        limit #{limit}
    </if>

</select>

运行此查询时的抱怨是:

 ### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntax
ErrorException: You have an error in your SQL syntax; check the manual that corr
esponds to your MySQL server version for the right syntax to use near 'left oute
r join grasummarypriceinfo summarypriceinfo on order.totalPrice_id = su' at line
 33

我简直气馁。我的选择中看不到任何错误...

你有什么线索吗?

4

1 回答 1

1

您正在使用 SQL 关键字order作为表别名。这会导致 MySQL 出错。例如,我刚刚在我的一张表上尝试了这个查询:

mysql> select order.film_id, order.title from film order 
       where order.film_id > 100 limit 4;

并得到同样的错误:

ERROR 1064 (42000): 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 'where order.film_id > 100 limit 4' at line 1

于 2012-07-11T02:53:43.043 回答