将SQL查询转换为IBatis / MyBatis查询

时间:2016-06-06 18:14:04

标签: sql oracle mybatis ibatis

我是Ibatis的新手并且还在学习它。我遇到了这个需要转换为Ibatis查询的SQL查询。

我尝试使用CDATA标记并尝试了一些迭代器标记,但它并没有为我解决问题。这是我的疑问:

SELECT comp_small_name
FROM table_company
WHERE companyid IN (
        SELECT agentid
        FROM (
            SELECT *
            FROM table_comp_price
            WHERE companyid = #compid#
            ORDER BY companyid DESC
            WHERE ROWNUM <= 2
            )
        )

这适用于Oracle数据库。

1 个答案:

答案 0 :(得分:1)

Method 1

SELECT comp_small_name
    FROM table_company
    WHERE companyid IN (
            SELECT agentid
            FROM (
                SELECT *
                FROM table_comp_price
                WHERE companyid = #compid
                ORDER BY companyid DESC
                WHERE <![CDATA[ ROWNUM <= 2 ]]>
                )
            )

或者您也可以使用以下Method 2

 SELECT comp_small_name
    FROM table_company
    WHERE companyid IN (
            SELECT agentid
            FROM (
                SELECT *
                FROM table_comp_price
                WHERE companyid = #compid
                ORDER BY companyid DESC
                WHERE ROWNUM &lt;= 2
                )
            )