It’s like this. There is a field KS_ZKZ in my table. This field is not unique in the table. Each student number appears multiple times. Now I want to perform paging query based on this student number:
First remove duplicate student numbers and arrange them in ascending order:
SELECT DISTINCT(KS_ZKZ) from ZK.T_BYSQ_KS_KC ORDER BY KS_ZKZ ASC
After having this query result, I want to query the data from rownum a to b of this result:
SELECT KS_ZKZ,ROWNUM FROM
(SELECT DISTINCT(KS_ZKZ) from ZK.T_BYSQ_KS_KC ORDER BY KS_ZKZ ASC)
WHERE ROWNUM >=10 AND ROWNUM<=20
But a problem arises: The following are the query results. .
Why can’t it be found?
PHPz2017-05-17 10:06:43
rownum is just a pseudo column. You just need to check the rownum in the layer inside, for example
SELECT KS_ZKZ FROM
(SELECT DISTINCT(KS_ZKZ), ROWNUM rn from ZK.T_BYSQ_KS_KC ORDER BY KS_ZKZ ASC)
WHERE rn between 10 AND 20
某草草2017-05-17 10:06:43
The judgment of rownum must start with 1. For example, =1 and <5 are all valid, but =2 and >7 must first find out the result set and then query through sub-statements (rownum requires an alias)