Page 94 - SQL
P. 94

FROM Employee;


        In this example, you use an ORDER clause to partition – or group – the rows retrieved by the SELECT
        statement based on employees' job titles, with the results in each group sorted based on the
        numbers of sick leave hours that employees have used.



                                                                                            Cumulative
          BusinessEntityID      JobTitle      SickLeaveHours       Percent Rank
                                                                                            Distribution

                                Application
          267                                 57                   0                        0.25
                                Specialist


                                Application
          268                                 56                   0.333333333333333        0.75
                                Specialist


                                Application
          269                                 56                   0.333333333333333        0.75
                                Specialist

                                Application
          272                                 55                   1                        1
                                Specialist


                                Assitant to
                                the Cheif
          262                                 48                   0                        1
                                Financial
                                Officer

                                Benefits
          239                                 45                   0                        1
                                Specialist


          252                   Buyer         50                   0                        0.111111111111111


          251                   Buyer         49                   0.125                    0.333333333333333

          256                   Buyer         49                   0.125                    0.333333333333333


          253                   Buyer         48                   0.375                    0.555555555555555

          254                   Buyer         48                   0.375                    0.555555555555555



        The PERCENT_RANK function ranks the entries within each group. For each entry, it returns the
        percentage of entries in the same group that have lower values.

        The CUME_DIST function is similar, except that it returns the percentage of values less than or equal
        to the current value.


        PERCENTILE_DISC and PERCENTILE_CONT


        The PERCENTILE_DISC function lists the value of the first entry where the cumulative distribution is




        https://riptutorial.com/                                                                               76
   89   90   91   92   93   94   95   96   97   98   99