# 我如何通过按降序排列排序和按升序排序价格

``````SELECT
`users`.`id` AS `refId`,
`tutor_subjects`.`id`,
`tutor_subjects`.`user_id`,
`users`.`role_id`,
`users`.`email_verified_at`,
`user_profiles`.`photo`,
`user_profiles`.`gender`,
`user_profiles`.`first_name`,
`user_profiles`.`last_name`,
`user_profiles`.`overview_video_file`,
`user_profiles`.`tag_line`,
`user_profiles`.`profile_slug`,
`user_profiles`.`hourly_rate`,
`user_profiles`.`city`,
`user_profiles`.`state`,
`cities`.`name` AS `city_name`,
`states`.`name` AS `state_name`,
(
SELECT
COALESCE(AVG(course_reviews.rating),
0)
FROM
course_reviews
WHERE
course_reviews.tutor_id = tutor_subjects.user_id
LIMIT 1
) AS average_rating,(
SELECT
COUNT(*)
FROM
course_reviews
WHERE
course_reviews.tutor_id = tutor_subjects.user_id
LIMIT 1
)
FROM
`tutor_subjects`
INNER JOIN
`users`
ON
`users`.`id` = `tutor_subjects`.`user_id`
INNER JOIN
`user_profiles`
ON
`user_profiles`.`user_id` = `tutor_subjects`.`user_id`
LEFT JOIN
`cities`
ON
`cities`.`id` = `user_profiles`.`city`
LEFT JOIN
`states`
ON
`states`.`id` = `user_profiles`.`state`
LEFT JOIN
ON
WHERE
(
`category_id` IN(182) OR `categories_sub_id` IN(182)
) AND EXISTS(
SELECT
*
FROM
`users`
WHERE
`role_id` = 3 AND users.id = tutor_subjects.user_id
) AND(
`gender` = 'Male' OR `gender` = 'Female'
) AND EXISTS(
SELECT
*
FROM
`tutor_locations`
WHERE
tutor_locations.user_id = tutor_subjects.user_id
) AND EXISTS(
SELECT
*
FROM
`tutor_locations`
WHERE
`lesson_mode` IN(2, 0, 1) AND tutor_locations.user_id = tutor_subjects.user_id
)
GROUP BY
`tutor_subjects`.`user_id`
ORDER BY
`average_rating`
DESC
LIMIT 10 OFFSET 0
``````