3

我有一个国家列表

SELECT * FROM COUNTRIES

COUNTRY
--------------
Austria
Belarus
Belgium
Finland
France
Iceland
Ireland
Switzerland

我将如何选择它作为 2 列,例如

COLUMN1          COLUMN2
-------          -------
Austria          Belarus
Belgium          Finland
France           Iceland
Ireland          Switzerland

谢谢。

4

3 回答 3

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;
于 2013-03-08T12:01:47.070 回答
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)
于 2013-03-08T12:18:58.543 回答
0

我想您可以使用子查询分解来完成此操作

示例查询

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
于 2013-03-08T12:15:25.030 回答