我有一个国家/地区列表
SELECT * FROM COUNTRIES
COUNTRY
--------------
Austria
Belarus
Belgium
Finland
France
Iceland
Ireland
Switzerland
我如何选择2列,例如
COLUMN1 COLUMN2
------- -------
Austria Belarus
Belgium Finland
France Iceland
Ireland Switzerland
感谢。
答案 0 :(得分:5)
select country, next_country
from
(select country,
lead(country) over (order by country) next_country,
row_number() over (order by country) rnk
from countries
)
where mod(rnk,2)=1;
答案 1 :(得分:3)
select
max(case mod(rownum - 1, 2) when 0 then country end) column1,
max(case mod(rownum - 1, 2) when 1 then country end) column2
from countries
group by floor((rownum - 1) / 2)
order by floor((rownum - 1) / 2)
答案 2 :(得分:0)
我想您可以使用Subquery Factoring
完成此操作示例查询
WITH
countrycolumn1 AS (
SELECT * FROM COUNTRIES where COUNTRY='some condition'),
countrycolumn2 AS (
SELECT * FROM COUNTRIES COUNTRY='some condition' )
SELECT col1.country as COLUMN1 , col2.country as COLUMN2
FROM countrycolumn1 col1,countrycolumn2 col2
WHERE col1.countrytype == col2 .countrytype