Findout the Least Null Values column and print out that column records ?

I `ve 1 table with 3 colums A,B,C
A B C
1 3 5
4 null 6
8 2 null
null 1 null
null null 9
5 null 6
3 5 7
null null 3

Showing Answers 1 - 6 of 6 Answers

vinay

  • Feb 16th, 2016
 

It should print out null 1 nll

  Was this answer useful?  Yes

Paurian

  • Feb 16th, 2016
 

A surprise to me, using CASE statements was slightly faster, and had the exact same execution plan. People would prefer this code over the SUM( ISNULL( ... ) ) answer because the intent is more clearly understood with "CASE WHEN A IS NULL ..."

Code
  1. SELECT

  2.   CASE

  3.     WHEN A < B AND A < C THEN A

  4.     WHEN B < A AND B < C THEN B

  5.     WHEN C < A AND C < B THEN C

  6.   END AS least_null_value

  7. FROM

  8.   (

  9.     SELECT

  10.       SUM( CASE WHEN A IS NULL THEN 1 END ) AS A,

  11.       SUM( CASE WHEN B IS NULL THEN 1 END ) AS B,

  12.       SUM( CASE WHEN C IS NULL THEN 1 END ) AS C

  13.     FROM

  14.       LNV

  15.   ) AS inner_query

  16.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions