Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grouping sections

Status
Not open for further replies.

TheDash

MIS
Mar 25, 2004
171
US
Hello,

I have a query like select a, b, c from tab1
It results

10 100 1000
10 110 1100
10 120 1200
20 200 2000
20 210 2100
20 220 2200

Any idea how I can retrieve the data like this:

10 100 1000
110 1100
120 1200
20 200 2000
210 2100
220 2200

i.e the column a should only appear once....

Thanks in advance.



 
One way to do this is with the "lag" function, which allows you to monitor whether the value in the column "a" has changed from the previous row. That, in turn, enables you to decide whether to print or suppress "a" in the current row.

Code:
select decode(a-prev_a, 0, null, a), b, c from
  (select a, b, c, lag(a, 1, a-1) over (order by a, b, c) as prev_a
    from tab1
  )
 
if its just for display purposes you can use the sqlplus break command


eg

break on a
select * from tab1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top