Before using MySQL and Informix databases, it is easy to look up the first 10 data in a table:
Most original version:
Select Top * from Student
Of course, we can also write a bit more complex, such as some additional query conditions?
For example, query the first 10 students with scores greater than 80 points
Added version of where query condition:
Select Top * from Table where > the
But!! There is no top in Oracle!!!! So how do we do that?
Well, you can use rownum!.
Original version in Oracle
Select * from where < Ten
There seems to be no complicated place up there. But the question is, if we still want to add a score greater than 80?
It's really hard for me, the Oracle beginner. Here directly posted out, hope can let some people less cost some force!
Oracle adds a where query condition version
Select * from ( Select rownum rn,a.*fromwhere> where<Ten
Simply analyze the above code. In fact, the first 10 data in the embedded SQL query result is queried by the embedded SQL statement, and then the data with the score greater than 80 is selected.
Finally attach MyBatis code?
<SelectId="Selectstudent" ParameterType="HashMap" Resultmap="Baseresultmap"> Select * from ( SelectRowNum RN, A.* fromStudent AwhereSTATUS= ' About' andScore<![cdata[>]]>#{scores,jdbctype=INTEGER}) whereRn<![cdata[<=]]>#{ Number, Jdbctype=INTEGER} </Select>
The above scores and number are variables
It's a little bit of a broken-down reading. I hope I can help you meet the same problem with my friends.
Oracle combines mybatis for table Top 10