Min values

  • hey guys for some reason the following is not giving me the minimum values....

    select

    KPAIDS_NO, min(nullif(Test_Result,Null)), Test_Type

    From

    Registry_Laboratory_Tests inner join Laboratory_Tests

     

    while it actually outputs min for some it doesn't for other fields.

    can anyone explain why?

    thx bros 

  • What do you mean it does for some fields and not for others?  You have asked only for the min of test_result.  I'm assuming you are grouping by KPAIDS_NO and Test_type even though you didn't show that. 

    Or are you indicating that you get NULLs for test_result sometimes?  That would be normal if your data contains nulls.

    James.

  • i'm actually surprised my self. when i compare the resultset of the query to that of the table i realized it didn't return the min of some values.

    Look at the following resultset: max vs min

    MAX

    KPAIDS_NO  Result

    00003C1    2000           

    00005M     554                  

    00006M     340                  

    00016C1    87                  

    00017C1    847                  

    00020C1    93                   

    00021C1    90                   

    00023C1    26                   

    00025C1    193                  

    00029C1    1965                 

    00030C1    76                   

    00031C1    426                  

    00032C1    538                  

    00034C1    537                  

    00035C1    99                   

    00037C1    922                  

    00039C1    799                  

    00040C1    57       

    MINIMUM     

    KPAIDS_NO  Result

    00003C1    2000               

    00005M     554                

    00006M     340                

    00016C1    105                

    00017C1    760                

    00020C1    104                

    00021C1    448                

    00023C1    113                

    00025C1    193                

    00029C1    1563               

    00030C1    220                

    00031C1    426                

    00032C1    316                

    00034C1    233                

    00035C1    332                

    00037C1    1105               

    00039C1    738                

    00040C1    57                  

                            

  • I just check the table design and find that Result is of char type.

    stupid designer 

  • Hi ,

    If TestResult is a varchar column then convert it into integer and then perform the Min or Max on it.

     

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply