Solved

sql query help fitst not null

Posted on 2011-02-27
3
220 Views
Last Modified: 2012-05-11
I have a table

ID   Rank1 Rank2 Rank3
112  1         2            Null

I want to write a query that shows the rank for the above example it should display result as 2
ID   Rank1 Rank2 Rank3
112  1         Null        3

for above it should show result as 1

ID   Rank1 Rank2 Rank3
112  Null        Null       2

for above it should show  result as zero

ID   Rank1 Rank2 Rank3
112  Null        2        2


for above it should display 0




As you can see i want to show the lowest rank before first null




0
Comment
Question by:Angela4eva
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
select case when rank1 is null then 0
  when rank2 is null then rank1
  when rank3 is null then rank2
  else rank3 end
  from yourtable
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
Comment Utility
select case
when rank1 is null then 0
when rank2 is null then 1
when rank3 is null then 2
else null
 end Result
  from YourTable

Raj
0
 

Author Closing Comment

by:Angela4eva
Comment Utility
thank you
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now