473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Order a select

4
I try to order the next codes of the column "codbobn2" (varchar2(7)). If i do the simple
"order by codbobn2 asc" I obtain:

9602915
9703046 --> mother
9703995
9783046 --> child of 9703046
9793046 --> child of 9703046

But I want to order like this, because the codes whose 3rd position <> '0' are
childs of the code whose 3rd position = '0'.

9602915
9703046 --> mother
9783046 --> child of 9703046
9793046 --> child of 9703046
9703995

I thougth to replace the 3er position of all values = '0' and after order, or something
like this but I don't know how can do this?
Mar 3 '10 #1
6 1675
rski
700 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. order by substr(codbobn2,3)
  2.  
Mar 3 '10 #2
sgfbio
4
Thank you for your quick response but perhaps I haven't explain well what I want to obtain: I have to order in 2 ways at the same time:

* the codes by codes (or codbobn2) asc
* but inside this first sort, a second sort by code "mother" (substr(codbobn2,3)=0)
and childs (same code as the mother but the substr(codbobn2,3) <> 0).

I tried your answer but the result it isn't what I wanted:

9602915
9703046
9703995
9793046

(and the 9783046 "disappears")
Mar 4 '10 #3
rski
700 Expert 512MB
That
Expand|Select|Wrap|Line Numbers
  1. select * from example order by substr(codbobn2,4), substr(codbobn2,3);
  2.  
returns
Expand|Select|Wrap|Line Numbers
  1. 9602915   
  2. 9703046   
  3. 9783046   
  4. 9793046   
  5. 9703995 
  6.  
I've checked it. Is that what you want?
Mar 4 '10 #4
OraMaster
135 100+
The data you posted is not sufficient. Try to post some more data and also explain logically which codes you want to be the childs of another code which have zero at 3rd position.
Mar 4 '10 #5
sgfbio
4
Sorry....

Thank you, it's what I wanted
Mar 5 '10 #6
amitpatel66
2,367 Expert 2GB
Can you please confirm that the third digit of PARENT records will always be 0?
Mar 10 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Irene | last post by:
Hi all again, Well, I have my Athletics database with Athletes, Competitions, Scores tables. I have a ranking query where I get back the list of the competitions-athletes and scores...
1
by: Thomas Schoen | last post by:
Hi, is it possible to use a parameter of a plpgsql-function to order a selection inside the function? What i would like to do is pass a column-name/alias-name to a plpgsql function and use...
104
by: Beowulf | last post by:
I have the view below and if I use vwRouteReference as the rowsource for a combo box in an MS Access form or run "SELECT * FROM vwRouteReference" in SQL Query Analyzer, the rows don't come through...
29
by: pb648174 | last post by:
I have the following basic statements being executed: Create a temp table, #TempPaging Insert Into #TempPaging (Col1, Col2) Select Col1, Col2 From SomeOtherTable Order By Col2, Col1 Select...
13
by: bevanward | last post by:
Hi All I am finding unexpected results when inserted into a newly created table that has a field of datatype int identity (1,1). Basically the order I sort on when inserting into the table is...
5
by: Nick Weisser | last post by:
Hi there, I'm not sure how to select the last 3 items in ascending order. This does the trick in descending order: select * from user_menu_main where deleted = 0 and hidden = 0 order by...
3
by: Beowulf | last post by:
I was just messing around with some ad hoc views and table returning UDFs today so I could look at and print out data from a small table and noticed something strange. If I stick my select...
3
by: Yobbo | last post by:
Hi All My query is as follows: SELECT STRINGTEXT, TOKENID FROM WEBSTRINGS WHERE TOKENID IN (6,20,234,19,32,4,800,177) All I want is my resultset to come back in the order that I have...
3
by: Hartmut Dippon | last post by:
Hi all, I hope somebody can help me with following problem: I have an application where I can drag&drop files/dirs from within explorer onto my form. If multiple files/dirs are selected I...
4
by: fluff | last post by:
Hello. I want to display some data from a database in a certain order. I have a table with columns A, B, Date. I want to display the records that have data in column A first and I want those...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.