2

在表中有一个名为 status 的列,它可以有 1 或 2。现在我想选择这样的模式

First Row 1
Second Row 2
Third Row 1
Fourth Row 2
......
4

6 回答 6

2

对于偶数行

select * from emp where rowid%2 = 0;

对于奇数行

select * from emp where rowid%2 != 0;
于 2016-12-09T10:13:24.923 回答
1

甲骨文:

 SELECT * from
    ( SELECT a1.*,rank() over (partition BY status order by rownum) RNK FROM TABLE1 a1
     )
    ORDER BY rnk,status 
    

Sqlfiddle:

于 2012-12-26T13:07:53.597 回答
1

微软 SQL:

select t1.*, (RN % 2)+1 as [STATUS] from
(
  select t.*, ROW_NUMBER() OVER (ORDER BY <ORDER COLUMN NAME HERE>) as RN
) t1
于 2012-12-26T13:10:35.250 回答
0

尝试这个

select * from (select table.* ,rownum k from table) where mod(k,2)<>0;
于 2012-12-26T12:57:49.447 回答
0

尝试这个:

SELECT e1.* FROM Employee e1
INNER JOIN  
(
    Select e2.*, ROW_NUMBER() OVER (ORDER BY <Column Names>) AS RN FROM Employee e2

)E2 
ON e1.eid=e2.eid
where e2.RN%2=0
于 2014-01-17T16:32:41.790 回答
0

要获取 ODD 记录,请使用以下内容:

SELECT e1.* FROM Employee e1 INNER JOIN
( Select e2.*, ROW_NUMBER() OVER (ORDER BY ) AS RN FROM Employee e2 )E2 ON e1.eid=e2.eid where e2.RN%2=1
于 2014-01-17T16:45:58.127 回答