DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: Need Help in Order By.,

  1. #1
    Join Date
    Jul 2007
    Posts
    21

    Need Help in Order By.,

    Hi All -

    i have a table TEST111 which have the following data..,

    Code:
    SQL> SELECT * FROM TEST11
      2  /
    
    POSNEG
    ----------
    RR1
    RR2
    RR3-
    RR1-
    RR2-
    RR3
    RR3+
    RR2+
    RR1+
    i want the output to be displayed as

    Code:
    RR1-
    RR1
    RR1+
    RR2-
    RR2
    RR2+
    RR3-
    RR
    RR3+
    Could any one help?

    Thanks

  2. #2
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    Code:
    select  posneg
    from    test11
    order   by substr(posneg,1,3),decode(substr(posneg,4,1),'-','1','+','3','2')
    ;
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  3. #3
    Join Date
    Jul 2007
    Posts
    21
    Thanks PAVB.

    That worked like wat i want.

    Thanks..,

  4. #4
    Join Date
    Jul 2007
    Posts
    21
    hi PAVB -

    Just a small change.

    if i have RR10,RR10-,RR10+, i am getting the output as follows,

    Code:
    SQL> SELECT   POSNEG
      2  FROM     TEST11
      3  ORDER BY SUBSTR(POSNEG,1,3),
      4           DECODE(SUBSTR(POSNEG,4,1),'-','1',
      5                                     '+','3',
      6                                     '2');
    
    POSNEG                                                                          
    ----------                                                                      
    RR1-                                                                            
    RR1                                                                             
    RR10-                                                                           
    RR10                                                                            
    RR10+                                                                           
    RR1+                                                                            
    RR2-                                                                            
    RR2                                                                             
    RR2+                                                                            
    RR3-                                                                            
    RR3                                                                                                                                                  
    RR3+                                                                            
    
    12 rows selected.
    But, i want RR10,RR10-,RR10+ to be displayed after RR3+.

    Could you help?

    Thanks

  5. #5
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    You already got your free service on this one and you blew it up because of wrong/incomplete specifications.

    Now is your turn, you do something and hopefully somebody will review it.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  6. #6
    Join Date
    Sep 2007
    Posts
    36
    How's this for a wordy solution?

    SELECT posneg
    FROM test11
    ORDER BY LPAD(SUBSTR(posneg,3,LENGTH(REPLACE(REPLACE(posneg, '-', NULL), '+', NULL))-2), 5),
    DECODE(SUBSTR(posneg,(LENGTH(REPLACE(REPLACE(posneg, '-', NULL), '+', NULL)))+1,1),'-','1',
    '+','3',
    '2');

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width