Need help to display 2 rows as consolidated column
Made this image to illustrate the problem
Thank you for your help
问问题
112 次
2 回答
3
如果您只需要 2 个城市,那么使用分析函数可能很简单:
select distinct studentname
, min(city) over ( partition by studentname ) as city1
, min(street1) over ( partition by studentname ) as street1
, case when min(city) over ( partition by studentname )
<> nvl( max(city) over ( partition by studentname ), 'x')
then max(city) over ( partition by studentname ) end as city2
, case when min(street) over ( partition by studentname )
<> nvl( max(street) over ( partition by studentname ), 'x')
then max(street) over ( partition by studentname ) end as street2
from my_table
尽管我必须补充一点,您可能不应该这样做。如果学生有 3 个地址会怎样?
于 2012-04-13T16:15:05.207 回答
2
我认为您对此的思考方式不正确。
您应该为“Ted”返回 2 行并使用您的视图/报告代码操作输出。这会容易得多,并且如果您的要求发生变化,您可以非常快速地更改视图/报告。
于 2012-04-13T14:53:25.453 回答