Home » SQL & PL/SQL » SQL & PL/SQL » order by multiple columns (Oracle 11.2g windows 2008R2)
order by multiple columns [message #598004] Wed, 09 October 2013 13:15 Go to next message
anncao
Messages: 87
Registered: August 2013
Member
I have a query to pull the first contact of students.
The table has all contacts like parent/guardian, friends family, emergency contact etc.

I would like to the first primary contact in this order,
1. initial contact, 2. same as student address and also have to be parents,
3. live with and also a parent, 4. parents 5. friends.

I don't know how to pull 2 and 3 . because it looks like it needs to concatenate the columns.

here is my initial query

Select Min(U2.Id) Keep (Dense_Rank First Order By U2.Initial_Contact Desc, U2.Same_As_Students_Address Desc,u2.lives_with DESC,U2.Guardian Desc)
From Contacts

how to achieve 2 and 3?

The table script is attached. All the above columns are 1 or 0.

  • Attachment: table.txt
    (Size: 2.50KB, Downloaded 1175 times)
Re: order by multiple columns [message #598005 is a reply to message #598004] Wed, 09 October 2013 13:18 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Hi,

Please post the table DDLs and insert statements. The rule which you have stated is a bit vague. How are those 5 values stored, insert statements will help us better understand the data.
Re: order by multiple columns [message #598008 is a reply to message #598005] Wed, 09 October 2013 13:30 Go to previous messageGo to next message
anncao
Messages: 87
Registered: August 2013
Member
The contact are all confidential info, it is hard for me to generate data.

I made an exmaple of one student in the attached file with fake data, and the ddl is in the attachment of my orginal post

[Updated on: Wed, 09 October 2013 13:33]

Report message to a moderator

Re: order by multiple columns [message #598010 is a reply to message #598008] Wed, 09 October 2013 13:39 Go to previous message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
I am afraid, not everybody like me would like to open/save the attachment. Please post the same thing using [ code] [ /code] tags(without the spaces I mentioned after the braces).
Previous Topic: partition name based on data
Next Topic: error
Goto Forum:
  


Current Time: Thu Apr 25 16:28:11 CDT 2024