sql - Display the minimum value from 3 columns -


i have table follows

**date        col1  col2  col3**  1-jan-2016    -98    25     15 19-jan-2016    25    -79    20 25-dec-2015   -12    24     89 

i have find minimum value col1, col2, col3, , display date of record.

in case result should 1-jan-2016 -98

you can in plsql way using least function

  declare   cursor c1 select date_column,least(col1, col2, col3) least_value yourtable;   begin   in c1 loop   dbms_output.put_line(a.date_column || ' ' || a.least_value);   end loop;   end; 

you can in simple sql well:

 select x.date_column, x.least_value          (select date_column, least(col1, col2, col3) least_value yourtable) x             x.least_value = (select min(least_value)                                         (select least(col1, col2, col3) least_value yourtable)) 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -