从此:
Hotel Type Room Guest From To
------------------------- ------ ---- ----------------------------------------- --------- ---------
University Inn & Suites Double 101 George Brown 11-SEP-10 14-SEP-10
University Inn & Suites Double 101 George Brown 11-OCT-10 13-OCT-10
University Inn & Suites Double 102
University Inn & Suites Double 103
University Inn & Suites Double 104
University Inn & Suites Double 105
University Inn & Suites Family 106 George Brooks 22-SEP-10 27-SEP-10
University Inn & Suites Family 107
University Inn & Suites Single 201 Sandra Williams 15-SEP-10 19-SEP-10
University Inn & Suites Single 201 Liz Armstrong 16-SEP-10 18-SEP-10
University Inn & Suites Single 201 Craig Harper 19-SEP-10 22-SEP-10
University Inn & Suites Single 202 Roger Harris 03-SEP-10 10-SEP-10
University Inn & Suites Single 202 Tonya Harris 23-SEP-10 27-SEP-10
University Inn & Suites Single 203
University Inn & Suites Single 204
University Inn & Suites Single 205
到这个
Hotel Type Room Guest From To
------------------------- ------ ---- ----------------------------------------- --------- ---------
University Inn & Suites Double 101 George Brown 11-SEP-10 14-SEP-10
George Brown 11-OCT-10 13-OCT-10
102
103
104
105
Family 106 George Brooks 22-SEP-10 27-SEP-10
107
Single 201 Sandra Williams 15-SEP-10 19-SEP-10
201 Liz Armstrong 16-SEP-10 18-SEP-10
Craig Harper 19-SEP-10 22-SEP-10
202 Roger Harris 03-SEP-10 10-SEP-10
Tonya Harris 23-SEP-10 27-SEP-10
203
204
205
答案 0 :(得分:5)
这是您正在显示的表格的结构(或)是报告的结果吗?
我的猜测是它是SQLPLUS报告的结果。如果是这种情况,并且您希望酒店名称出现一次(直到它更改),您可以指定
Break on hotel;
Select hotel, type, room_guest
from hotels
order by hotel;
以达到理想的效果。
如果是结构,则不能删除除第一行以外的所有列值。 (事实上,就数据库而言,没有什么比第一行更像)。如果您尝试消除重复数据,请查看规范化表格。
http://en.wikipedia.org/wiki/Database_normalization \
请发布表格说明和工具(如果有的话),以便为您的案例获得适当的答案。
答案 1 :(得分:3)
如何使用lag
访问上一行并检查它是否与当前行具有相同的值?
select decode(hotel,
lag(hotel, 1, null) over (order by hotel, room, ...), null,
hotel) as "Hotel"
from ...