开发者

using DECODE with FIRST ORDER_BY in an sql query

I have started studying SQL, and while browsing a couple of reading materials I stumbled on this query:

SELECT MAX(SALARY) KEEP (DENSE_RANK FIRST ORDER BY 
    DECODE (SALARY, NULL, NULL, MONTHLY_SAL) NULLS LAST)

I have tried reading up on 开发者_如何学Gowhat this means and have come up with the following (please excuse my long winded and noobish explanations):

  1. DECODE (SALARY, NULL, NULL, MONTHLY_SAL) NULLS LAST - will return MONTHLY_SAL unless SALARY is NULL. NULL salaries will also be listed last.

  2. MAX(SALARY) - will give the maximum salary that will result from (DENSE_RANK ...)

So my questions are these:

  1. Will MAX(SALARY) only give one value? or will it return the whole all rows and display the max salary? (i.e. if I have 2 rows having salaries of 1000 and 2000, the result will be two rows having values of 2000)

  2. What is the "total" effect of DENSE_RANK FIRST ORDER BY DECODE (...)? I have only seen examples of ORDER BY and am not sure what will happen if this is coupled with DECODE.

thank you


1) yes, one value

2) when you omit KEEP (DENSE_RANK... you'll get the max salary of all records. With KEEP (DENSE_RANK... you'll get max salary out of all records which have the smallest monthly_sal and a non-null salary. The job of the ´DECODE´-expression is to exclude records with null salary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜