表A
columna --------- A B C : : Z
以下是如何选择偶数行。我写过像这样的查询
select * from (select row_number()over(order by no asc ) as number
from number
where mod(number,2)=0)as even
它不起作用。
答案 0 :(得分:1)
尝试
select *
from
(
select *, row_number() over (order by columna) as rnum
from tablea
) q
where mod(rnum, 2) = 0
输出:
| NO | RNUM | |----|------| | B | 2 | | D | 4 | | F | 6 |
这是 SQLFiddle 演示
答案 1 :(得分:0)
SQL> desc member_list
Name Null? Type
------------------------------- -------- ----
E_MAIL VARCHAR2(50)
NAME VARCHAR2(50)
select e_mail from (select rownum row_num, e_mail from member_list)
where mod(row_num,2) = 0 -- EVEN
给你一个例子试试这个
答案 2 :(得分:0)
WITH cte AS(
SELECT *
, ROW_NUMBER()OVER(ORDER BY no)AS RowNum
FROM number t
)
SELECT cte.* FROM cte
WHERE mod(RowNum,2) = 0
答案 3 :(得分:0)
不知道abt postgres但是在oracle你可以这样做
SELECT * FROM
(SELECT columna, ROWNUM RNUM
FROM tableA
ORDER BY columna)
where MOD(RNUM,2)=0