如何从报告中删除重复的列值

发布于 2024-10-03 03:58:07 字数 2861 浏览 2 评论 0原文

从这:

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

FROM THIS:

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

TO THIS

    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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

好倦 2024-10-10 03:58:07

这是您显示的表格结构(还是)报告的结果?

我的猜测是它是 SQLPLUS 报告的结果。如果是这种情况,并且您希望酒店名称出现一次(直到其更改),您可以指定

Break on hotel;

Select hotel, type, room_guest
  from hotels
  order by hotel;

以达到所需的结果。

如果是结构,则无法删除除第一行之外的所有列值。 (事实上​​,就数据库而言,没有什么比第一行更好的了)。如果您想消除重复数据,请考虑规范化您的表。

http://en.wikipedia.org/wiki/Database_normalization\

请发布表说明和工具(如果有),以便您获得适合您案例的答案。

Is this the structure of the table that you are showing (or) is it the result of a report?

My guess is it is the result of a SQLPLUS report. If that is the case, and you want the Hotel name to appear once (until it changes), you can specify

Break on hotel;

Select hotel, type, room_guest
  from hotels
  order by hotel;

to achieve the desired result.

If it the structure, you cannot delete the column values for all but the first row. (in fact, there is nothing like the first row as far as the database is concerned). If you are trying to eliminate duplicate data, then look into normalizing your table.

http://en.wikipedia.org/wiki/Database_normalization\

Please post the table description and the tool (if any) so that you'd get the appropriate answers for your case.

你的心境我的脸 2024-10-10 03:58:07

使用 lag 访问前一行并检查它是否与当前行具有相同的值怎么样?

select decode(hotel,
              lag(hotel, 1, null) over (order by hotel, room, ...), null,
              hotel) as "Hotel"
  from ...

How about using lag to access the previous row and check if it has the same value as the current one?

select decode(hotel,
              lag(hotel, 1, null) over (order by hotel, room, ...), null,
              hotel) as "Hotel"
  from ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文