Any trick to sort columns?

I have a particular issue to solve. I have a table as follows:
CREATE TABLE Trunk (
Port1 NUMBER,
Port2 NUMBER,
Port3 NUMBER
I will use a complex query to select 3 values from other places to populate Trunk table. On insertion, I'll have to make sure that Port1 < Port2 < Port3. Is there an easy trick to accomplish this?
So far I have this kind of stupid way to do it. As any savvy can see, if I have 4 columns to sort out, I will need a permutation of 24 subqueries in a big UNION. Doesn't scale well.
Please help. Thanks.
Matt
INSERT INTO Trunk VALUES (Port1, Port2, Port3)
SELECT x.Port, y.Port, z.Port FROM x, y, z
WHERE <expr> AND x.Port < y.Port AND y.Port < z.Port
UNION ALL
SELECT x.Port, z.Port, y.Port FROM x, y, z
WHERE <expr> AND x.Port < z.Port AND z.Port < y.Port
UNION ALL
SELECT y.Port, x.Port, z.Port FROM x, y, z
WHERE <expr> AND y.Port < x.Port AND x.Port < z.Port
UNION ALL
SELECT y.Port, z.Port, x.Port FROM x, y, z
WHERE <expr> AND y.Port < z.Port AND z.Port < x.Port
UNION ALL
SELECT z.Port, x.Port, y.Port FROM x, y, z
WHERE <expr> AND z.Port < x.Port AND x.Port < y.Port
UNION ALL
SELECT z.Port, y.Port, x.Port FROM x, y, z
WHERE <expr> AND z.Port < y.Port AND y.Port < x.Port;

Hi Friend
Inserting the values directly with insert,select statement is bit complex. i ve tried the combinations along with the functions decode and sign but it is too complex. the best alternative solution is like this . create a function as described below
create or replace function rec(a number, b number , c number) return varchar2 is
v varchar2(200);
begin
if (a>=b) and (b >=c) then           /* a>b>c */
v:= a||'|'||b||'|'||c;
elsif (a >=b ) and (c >=b) and (a >c )then     /* a>c>b */     
v:= a||'|'||c||'|'||b;
elsif (b >=a) and (a >=c)     then          /* b>a>c */
v := b||'|'||a||'|'||c;
elsif (b >=a) and (c >=a) and (b > c) then     /* b>c>a */
v:= b||'|'||c||'|'||a;          
elsif (c>=a) and (a>=b) then               /* c>a>b */
v:= c||'|'||a||'|'||b;          
else                               /* c>b>a */
v:= c||'|'||b||'|'||a;          
end if;
return v;
end;
create table tt(n1 number,n2 number,n3 number);
values are inserted like this
n1     n2     n3
3 2 1
3 1 2
2 1 3
2 3 1
1 2 3
1 3 2
select n1,n2,n3 , rec(n1,n2,n3) from tt;
output is like this
N1 N2 N3 RESULT
3 2 1 3|2|1
3 1 2 3|2|1
2 1 3 3|2|1
2 3 1 3|2|1
1 2 3 3|2|1
1 3 2 3|2|1
As you can see the result of the three columns coming thru a single column. what u need to do is just extract the required value to the required column using substr and instr functions.
Hope this helps you :-)
Please change the values and formatting as required if u want n1<n2<n3 , Pls make the necessary change in the
program .
Pls let me know if any difficulties
Rgds
Prakash Eranki
[email protected]
[email protected]

Similar Messages

  • A simple question about wrong sorting with multiple sort columns in Excel 2010

    Hi, everyone! I have encountered a problem that I don't know how to explain.
    So I post it here because I don't know if there is another more relevant forum...
    I have a data sheet with the students' scores for the course. 
    All the data were generated with the randbetween function,
    and pasted with the values.
    To rank the students by their performance,
    I did the sort with the column "total score" as the first sort-column
    and "final term" as the second.
    The weird thing to me is that the order of the data seems problematic.
    That is, all the rows are sorted correctly with the first sort-column.
    But for the rows with the same values of the first sort-column,
    there are some rows whose values of the second sort-column are out of order.
    (please look at the data file at
    www_dot_kuaipan_dot_cn/file/id_67204268108546068_dot_htm
    Please change the "_dot_" to the real literal dot.
    Especially the rows with 56.7 as the first sort-column value
    and some other values near the tail of the list.)
    I tried to manually input and sort the same values of both columns
    in a near-by region. The result was correct.
    When some friend copied all the data to paste in Notepad,
    and reload them in excel. The problem disappears.
    Some friend also tried to wrap a round function at the values of the 1st sort-column,
    the sorting order became correct!
    But they could not explain why either.
    How confusing! I even tried to swap the first and secod sort-column;
    the output was right.
    All the data were generated by randbetween function and pasted with values.
    Where could all the special characters, if any, come?
    Can anyone give me an explanation? I would be very grateful.
    Thanks in advance!

    Re:  Sort is not in proper order
    Sounds as if the data includes spaces or hidden characters that are affecting the sort.
    That is indicated by the fact that manually entering the data resolves the problem.
    Note:  You can use a public file storage website to hold your file and add the link to it in your post.
    Jim Cone
    Portland, Oregon USA
    Special Sort excel add-in (30+ ways to sort) - 3 week no obligation trial
    https://jumpshare.com/b/O5FC6LaBQ6U3UPXjOmX2

  • Problem  in  specifing the intial sorting column of  a report

    hi
    we have a report based on a table with 6 columns in our home page .we display all the six columns as sortable.
    we also need to sort the contents of the report by 4th column by default when ever the user logs in ,but what happens is ,report gets sorted automatically depening upon the previous sorting column selected
    is there any way of telling htmldb to sort the report by 4th column ..
    many thanks
    S.Jawahar

    hi ,
    this infotype has a interesting solution . In my case it was  for US country .
    We select the veteran status and this is field P0077-VETST  which is stored in DB table .
    Now based on this value and the molga of that pernr  we need to look at the T5UVT table for the combinations avaliable for MOLGA AND  VETST .
    Based on the config's of this table the screen values are getting populated .
    It dosent allow any combinations and the picked values are passed to the screen for fields Q0077-VETS1 VETS2 VETS3 VETS4 .
    Br,
    Vijay.

  • Sorting Columns in JTable Using Different Comparators

    Is there any way to sort each column in a JTable using different comparators?

    you'll have to write your own tableSorter

  • Any Program to sort by keywords faster than CS-PS6-Bridge For Keyword Search?

    To sort by keywords in (CS-PS6)-Bridge  one has to group all your folders under one overall folder. Then when you search by keywords (CS-PS6)-Bridge opens up all the photos in Bridge which take  avery long time. Since Lightroom Smart Previews open up smaller files will it open up all ones pictures faster? and then can it sort by keywords.
    I am assuming Lightroom  smart preview opens up a larger size file than CS6-PS-6-Bridge and thus is even slower.
    So the question becomes are there Any Program to sort by keywords faster than CS-6-Bridge For Keyword Search? i.e A program that doesn't have to open up a file to look at keywords or a way to open smaller thumbnails in Bridge?

    Really?
    You mean you can't just click on the Magnifying Glass in the Search Box like I can?
    Uploaded with plasq's Skitch!
    And then Select Rating?
    Uploaded with plasq's Skitch!
    And then click on the Third Dot and it will become a Star?
    Uploaded with plasq's Skitch!
    Or even use a Smart Album? File -> new Smart Album: My Rating -> is -> And there's click on the third dot to make it a star trick again?
    Regards
    TD

  • How to fix the width of sorting column about adf table ?

    I develop project with ADF in jdeveloper.
    When click on the sorting column header in adf table,it will adjust the width of the sorting column header.It will make page shifting.
    How can I do to avoid the adjusting ?
    How can I do to fix the width of soting table header?
    Any hint will be appreciated.
    Thank you!
    Message was edited by:
    user618145

    I have set the column width like this:
    in style.css:
    /** Column Settings **/
    af|column::header-text
    background-color:#F0EDE1;
    color:#000000;
    font-family:Arial,Helvetica,sans-serif;
    font-size:12px;
    font-weight:bold;
    padding-left: 2px;
    padding-right: 2px;
    padding-top: 3px;
    padding-bottom:3px;
    border-color: #B5B5B5;
    WIDTH: 120px;
    af|column::sortable-header-text
    background-color:#F0EDE1;
    color:#000000;
    font-family:Arial,Helvetica,sans-serif;
    font-size:12px;
    font-weight:bold;
    padding-left: 2px;
    padding-right: 2px;
    padding-top: 3px;
    padding-bottom:3px;
    border-color: #B5B5B5;
    WIDTH: 120px;
    and in jsp page,write like this:
    <af:panelBox text="test" width="1000" background="dark" >
    <af:table emptyText="" value="#{ftOverview.listOfTransefersVect}" var="transfers" width="100%" banding="row" bandingInterval="1">
    <af:column sortable="true" sortProperty="transactionId" headerText="#{resources['ft_overview.ref']}" formatType="text" width="39"
    noWrap="true">
    <af:outputText value="#{transfers.transactionId}" escape="false"/>
    </af:column>
    </af:table>
    </af:panelBox>
    but it seems doesn't work well.

  • Locking and sorting columns

    This is what I am trying to do:
    Lock the information in column A so it always stays there (1st, 2nd , 3rd, etc.)
    Sort Column C (total winnings) in descending order and keep the coresponding participants (column B ) with the amount.
    Create a value in Column D (4 behind Leader) that shows the difference between C3 and C4, C3 and c5, etc.
    The amounts and names are  filled from another sheet and change weekly. I can sort based on total winnings and the names follow. I can also create a formula to show the difference between the Leader and the next place participant however when I do a sort based on Total Winnings after the new values each week the Place and $Behind Leader always shift up and down. The information in Column A seems "locked" to the information in Columns B and C. The refernce in Column D is always Chris's amount and I want it to be refenced to the 1st place Participant.
    I hope I've explained this.
    Thanks - James
    2013 Standings
    Place
    Participant
    Total Winnings
    $ Behind Leader
    1st
    Chris
    $24.00
    2nd
    Ken
    $22.00
    -$2.00
    3rd
    Paul
    $20.00
    -$4.00
    4th
    Josh
    $18.00
    5th
    Kelly
    $16.00
    6th
    Greg
    $14.00
    7th
    Dave
    $12.00
    8th
    Darren
    $10.00
    9th
    Don
    $8.00
    10th
    Tony
    $6.00
    11th
    Suzanne
    $4.00
    12th
    James
    $2.00
    13th
    Spare 1
    $0.00
    14th
    Spare 2
    $0.00
    15th
    Spare 3
    $0.00
    16th
    Spare 4
    $0.00
    17th
    Spare 5
    $0.00
    18th
    Spare 6
    $0.00
    19th
    Spare 7
    $0.00
    20th
    Spare 8
    $0.00

    Hi j&s,
    Numbers uses a data base model that treats each row of a table as a single record. You can sort all or selected rows on the values in one or more column(s), but the whole row moves to maintain the integrity of each record.
    If you want some columns to be excluded from a sort, you need to remove those columns (or their data) from the table. Jerry has offered a way to do that for the rankings, but that solution will not resolve the issue of the 'leader board' cells acting badly in a sort.
    Here's an alternate. The first view is of the table(s) (with the participants in alphabetical order), just after the current totals had been entered.
    At this point, the Leader board, which pulls names and totals from the first three body rows of the data table, shows the correct cells, but these don't include the correct information.
    Note that column A does show the correct placing for each participant.
    The second view shows the same table(s) after the data table has bee sorted. The sort may be descending on column C (Totals) or ascending on column A (Place).
    Place is calculated from the Total values, using this formula:
    A2: =RANK(C2,C,largest-is-high)
    Fill down into the rest of the cells in column A. Any empty rows should be removed from the bottom of the table, or have zeros entered into their total column cells.
    The Leader board table has two formulas:
    A2: =OFFSET(Data :: $A$1,ROW()-1,1)
    Fill down to A4.
    This returns the name of the participant in the top body cell of column B of the data table.
    B2 contains the word "Leader"
    B3: =IF((OFFSET(Data :: $A$1,1,2)-OFFSET(Data :: $A$1,ROW()-1,2))>0,OFFSET(Data :: $A$1,1,2)-OFFSET(Data :: $A$1,ROW()-1,2),"Leader")
    Fill down to B4
    The root of this formula is OFFSET(Data :: $A$1,1,2)-OFFSET(Data :: $A$1,ROW()-1,2)
    This returns the total value from the first and second body cells in the total column, and subtracts the second from the first.
    The rest of the formula is an IF statement tohandle the occasions where there's a two or three-way tie for the lead. (image below) If the result is greater than zero, the subtraction is repeated and the result returned to the cell (B3); if the result is zero, the word :Leader: is returned to this cell.
    Placing the calculation in a separate table and using OFFSET, with a base cell (Data::A1) that is in a row defined as a Header row makes this table and its formulas immune from sorting of the Data table.
    Here's the tie, which arose when i added another 11 particpants to check sorting of the Place column:
    Regards,
    Barry
    Message was edited by: Barry (added image and notes on Tie case)

  • Any trick to managing apps in iTunes 9?

    Not sure if this question should be posted here or in the iTunes section ..
    I have my apps on pages sorted by the application type. I have utilities on page 2, 3, Games on page 4, 5, and so on. [Aside: I wish Apple implements grouping of apps on tabbed pages. Then I can display only games if I need to, without flipping through pages of app icons].
    If I install a new App, it adds the icon to the last page. If I drag and move that new app to page 2, then instead of cascading all icons through the rest of the pages, it puts the "extra" icon from the bottom of page 2 all by itself on a new page. I have to drag that on to top of page 3, and the process repeats itself until the last page has the added icon.
    This is tedious. Is there any trick in application pages management so that the icons "flow" down to the next pages if I insert an app on a page?

    Interesting idea but, unfortunately it didn't work. I am actually able to synch my apps by checking or unchecking one of the other options such as movies. Weird.
    Thanks for the idea though.

  • Changing Sort column

    I have a report that has different groups and is sorted by a particular column.
    I would like to be able to create an additional layout (in the trailer section) that executes the same query (in fact if it just uses the same data) but ordered by different column.
    How can this be done?
    I realise the lexical parameters could be used - how to do this via a trigger?
    Is there another way.simplier that would not involve rerunning the same basic query.
    The sort columns are in the detail and not group by columns.
    Thanks in advance for any help and direction

    I don't think that you can do this just by using one query. I mean same data twice but with different orders.
    In that case you need another query and second report layout within same report. You already know, what is the sort order for query one and query two, so in that case you don't need lexical parameters (if you go by this way).
    Another option is, run this report twice from JSP by passing sort column name to lexical parameter. It will create two PDFs but your report will have only one query.
    Third and best option is, on JSP ask user on which column he/she wants to sort and pass this column to lexical parameter in report.
    In your case, you don't need to set value for lexical parameter in form triggers. You can pass directly to lexical parameter from JSP.
    May be someone else can give better solution.

  • The 'sort columns' default behavior

    It seems the new sort columns remove the word "The" by default in a title listing. I'm curious to know if this action can be removed.
    Also, since it is apparently possible to pre-program sort column behavior, is it possible to always reverse to lastname, firstname in the sort composer column?

    I just thought since iTunes now comes pre-programmed to alphabetize without the "The" first, it might be possible to revert it to original behavior.
    I don't know if it's something that can be reverted, short of going back to a previous version of iTunes or finding something (a script?) to strip the entries in the Sort Name field for those songs.
    Looking at the tracks in my Library, it seems that at the point of updating, iTunes went through and stripped the initial 'The' from all the song titles and placed that in the Sort Name field. Tracks that don't start with 'The' and maybe similar articles like 'A' (I can't think of any in my library to check) do not have anything in the Sort Name field, and are thus sorted normally by the full title.
    The behavior of the program hasn't changed, but the song data that it operates on has.
    WRT iPod and contacts- last name and first name are two different fields in the contact information- the same switch is possible in AddressBook. But (and this is a BIG but) if, when entering the contact into AddressBook, you enter the full name into one field-either First Name or Last Name- you cannot change the order.
    What the iPod is doing is the same as you clicking another column heading in iTunes.

  • Sort columns in matrix report

    Hi all
    I create matrix report( in version 9i)
    I want sort columns of report
    when i use order by it sort rows but i want sort columns
    my query is like this:
    SELECT
    Code,
    name,
    DECODE(cons_code, '1', 'A',
    '2', 'B',
    '3','C',
    '4', 'D',
    '5', 'E') Activity,
    SUM(amnt) amount
    From Mytable
    Where ....
    group by
    Code,
    DECODE(cons_code, '1', 'A',
    '2', 'B',
    '3','C',
    '4', 'D',
    '5', 'E')
    my group base on code
    my columns base on Activity
    and cells are Amount
    my report result is:
    ........ B E D A C
    name1 1 1 1 1 2
    name2 3 4 8 6 1
    I want this :
    ........ A B C D E
    name1 1 1 1 1 2
    name2 3 4 8 6 1
    ....

    Hello,
    How about this?
    SELECT Code, name,
    DECODE(cons_code, '1', 'A', '2', 'B', '3','C', '4', 'D','5', 'E') Activity, SUM(amnt) amount
    From Mytable
    WHERE ....
    GROUP BY Code, name, DECODE(cons_code, '1', 'A', '2', 'B', '3','C', '4', 'D', '5', 'E')
    ORDER BY code, DECODE(cons_code, '1', 'A', '2', 'B', '3','C', '4', 'D', '5', 'E')

  • Is there any way to sort songs in iTunes library between mp3 versions and m4a versions.  Any help/guidance would be appreciated.

    Is there any way to sort itunes library between m4a and mp3 versions of songs.  If there is, any instructions and guidance would be most appreciated.  Thanks in advance.

    Hey, here's an article I found. It might help:
    Converting your iTunes purchases to another format:
    http://support.apple.com/kb/HT1550

  • IS THERE ANY TRICK TO CONNECT THE MACBOOK AIR TO A VGA PROJECTOR? (I HAVE PROPER APPLE CABLE)

    Is there any trick to connect the macbook air to a vga projector?
    (I have the Apple right cable).
    I'm a professor in Brazil and just starting using the macbook air...

    Hi LCMONTANARI,
    If you are having issues connecting an external display or projector to your MacBook Air, you may find the following articles helpful:
    OS X Mavericks: Connect multiple displays to your Mac
    http://support.apple.com/kb/PH13814
    Apple computers: Troubleshooting issues with video on internal or external displays
    http://support.apple.com/kb/ht1573
    Regards,
    - Brenden

  • Suggest Trick to sort?

    Hi all,
    I am trying to sort a segment column ,, its like 10-20 , 20-30 , 30-40 .... 80-90 , so on ,,
    I created one more segment sort column saying if above col value is 10-20 then 1 , if 20-30 then 2...
    But when i apply a filter , the outsome of order coming to like , 3, 4, 5 , ..2, 1
    I am trying to show this order in Chart view in legend..
    What i did to sort :
    1) I have created sort column, ..
    2) Filter condition column sorted in RPD based on Columns showing in The report , but no use ..
    3 ) if i sort on the sort column the month column (i have month column in the report ) get disordered.. which is again a major problem..
    Please give me some advice on that ..
    Thanks

    One other thought is fragmentation. If you record and erase a whole lot, then your files could be fragmented, which would affect performance. There are defragmenting programs, which I have never used, available such as Norton Utilities. What I do is after a project. Say an album. I back up my work on DVD, then reformat my Audio drives. You can try that if you suspect your disk. Save your work on DVD, or another drive. Erase the disk, then put your files back to that drive. It should assemble the files continuously. You will have to re assign your record path after doing this, since the song is moved from its former "address". In older versions of Logic, you had to "search for the missing files" which the machine would do at the click of a button, but now it seems to locate them automatically without this step. Only the record path must be reset. OR If your disk is nearly full, I understand that the disk has poorer performance along the outer edge. Finally, if you are playing back samples from say, a program that uses Disk streaming, and if those sample files are located on your system disk, or I suppose even on your Audio disk, that could be creating an exhausting work load. If this is the case, you should store such samples on a separate, dedicated Hard drive of their own.

  • How can I get (using API) the current sort column for some report

    hello,
    How can I get (using API) the current sort column for some report ? For example something like "fsp_sort_1_desc" - if the user sorts by the first column ?
    I cannot use the :REQUEST for this, sometimes the current sort column is not in the :REQUEST, but it is still active.
    I thought it was posssible by using
    APEX_UTIL.GET_PREFERENCE (
    p_preference IN VARCHAR2 DEFAULT NULL,
    p_user IN VARCHAR2 DEFAULT V('USER'))
    RETURN VARCHAR2;
    function, but I don't really know which preference should I pass as parameter.
    looking in WWV_FLOW_PREFERENCES$, i saw preferences_names like FSP4000_P527_R6281510839654570_SORT , I'm not sure how this name is formed.
    I'm using generic columns for that complex report (which has a flexible number of columns shown), and the idea is that sometimes I have to overwrite that sort column, in case the user chose the version of the report with fewer columns than the previous one.
    Can I get (using API) a list of all preferences set for some user ?
    Thank you,

    seems that it is FSP<app_number>P<pagenumber>R<regionnumber>_SORT.
    is there anyplace where I can get these kind of things documented ?
    Thank you.

Maybe you are looking for

  • The requested url was not found on this server songs

    firslty My Iphone is not recognised when i connect to itunes so cant do anything from laptop and secondly i can play movies and videos but all my music i go to play it and it says The requested URL wa not found on this server and the songs all stay o

  • Partition not showing up and cannot be mounted

    Hi, I have a Samsung 840 pro SSD installed on my macbook with Mountain Lion and earlier my computer froze then the computer was stuck on a white/grey screen for a while before rebooting finally. Since I reboot, my second partition is not showing up.

  • POST issue

    Hello i have the x48c platinum mobo. What I am facing is a boot problem. The problem is as follows : powering up my computer after it having been shut down for some hours or more, i don't get the POST message. The system starts, the fans start but i

  • ITunes Store Preview Script

    I downloaded from "Doug's Scripts" a while back a script that once you ran it would start playing the preview of the first song of an album in the iTunes store, and it would then go to song 2 play it, then 3, and so on... It now does not work in iTun

  • Regarding description of Infoobjects in Reports

    Hai I created the InfoObjects by giving the Length and its description . But when I create the Reports then I didn’t get the description of InfoObjects Fully . Why it is like that and what I have to do ??? Is there any limit for textual description o