original_string: public static function get_least_proficient_competencies_for_course($courseid, $skip = 0, $limit = 0) {
          global $DB;
  
          $fields = competency::get_sql_fields('c', 'c_');
          $params = array('courseid' => $courseid);
          $sql = 'SELECT ' . $fields . '
                    FROM (SELECT cc.competencyid, SUM(COALESCE(ucc.proficiency, 0)) AS timesproficient
                            FROM {' . course_competency::TABLE . '} cc
                       LEFT JOIN {' . self::TABLE . '} ucc
                                  ON ucc.competencyid = cc.competencyid
                                 AND ucc.courseid = cc.courseid
                           WHERE cc.courseid = :courseid
                        GROUP BY cc.competencyid
                       ) p
                    JOIN {' . competency::TABLE . '} c
                      ON c.id = p.competencyid
                ORDER BY p.timesproficient ASC, c.id DESC';
  
          $results = $DB->get_records_sql($sql, $params, $skip, $limit);
  
          $comps = array();
          foreach ($results as $r) {
              $c = competency::extract_record($r, 'c_');
              $comps[] = new competency(0, $c);
          }
          return $comps;
      }
code: public static function get_least_proficient_competencies_for_course($courseid, $skip = 0, $limit = 0) {
          global $DB;
  
          $fields = competency::get_sql_fields('c', 'c_');
          $params = array('courseid' => $courseid);
          $sql = 'SELECT ' . $fields . '
                    FROM (SELECT cc.competencyid, SUM(COALESCE(ucc.proficiency, 0)) AS timesproficient
                            FROM {' . course_competency::TABLE . '} cc
                       LEFT JOIN {' . self::TABLE . '} ucc
                                  ON ucc.competencyid = cc.competencyid
                                 AND ucc.courseid = cc.courseid
                           WHERE cc.courseid = :courseid
                        GROUP BY cc.competencyid
                       ) p
                    JOIN {' . competency::TABLE . '} c
                      ON c.id = p.competencyid
                ORDER BY p.timesproficient ASC, c.id DESC';
  
          $results = $DB->get_records_sql($sql, $params, $skip, $limit);
  
          $comps = array();
          foreach ($results as $r) {
              $c = competency::extract_record($r, 'c_');
              $comps[] = new competency(0, $c);
          }
          return $comps;
      }
code_tokens: public static function get_least_proficient_competencies_for_course ( $ courseid , $ skip = 0 , $ limit = 0 ) { global $ DB ; $ fields = competency :: get_sql_fields ( 'c' , 'c_' ) ; $ params = array ( 'courseid' => $ courseid ) ; $ sql = 'SELECT ' . $ fields . '
                    FROM (SELECT cc.competencyid, SUM(COALESCE(ucc.proficiency, 0)) AS timesproficient
                            FROM {' . course_competency :: TABLE . '} cc
                       LEFT JOIN {' . self :: TABLE . '} ucc
                                  ON ucc.competencyid = cc.competencyid
                                 AND ucc.courseid = cc.courseid
                           WHERE cc.courseid = :courseid
                        GROUP BY cc.competencyid
                       ) p
                    JOIN {' . competency :: TABLE . '} c
                      ON c.id = p.competencyid
                ORDER BY p.timesproficient ASC, c.id DESC' ; $ results = $ DB -> get_records_sql ( $ sql , $ params , $ skip , $ limit ) ; $ comps = array ( ) ; foreach ( $ results as $ r ) { $ c = competency :: extract_record ( $ r , 'c_' ) ; $ comps [ ] = new competency ( 0 , $ c ) ; } return $ comps ; }
docstring: Get the list of competencies that were completed the least times in a course.
  
  @param int $courseid
  @param int $skip The number of competencies to skip
  @param int $limit The max number of competencies to return
  @return competency[]
docstring_tokens: Get the list of competencies that were completed the least times in a course .