MySql查询中的多个顺序

时间:2016-02-29 06:13:03

标签: mysql sql database

我正在开发一个投票系统。 我在订购时面临问题。 基本上我想先获得最高排名和最高提名者。我使用" totalUserVoted"和" totalRating"在两个条件的降序但我的查询排序" totalUserVoted"。

我期待这个顺序的结果。

Ordering Image

这是我的SQL查询。

SELECT
  (SELECT (((SUM(`design`)*4)+(SUM(`usability`)*3)+(SUM(`creativity`)*2)+(SUM(`content`))*1))/ count(`nominee_id`) / 10
   FROM `sk_award_nominee_rating`
   WHERE `sk_award_nominee_rating`.`nominee_id`=`sk_award_nominee`.`nominee_id`) AS totalRating,
  (SELECT count(`nominee_id`)
   FROM `sk_award_nominee_rating`
   WHERE `sk_award_nominee_rating`.`nominee_id`=`sk_award_nominee`.`nominee_id`) AS totalUserVoted,
       `sk_award_nominee`.*,
       `sk_user`.`username`,
       `sk_user`.`email`,
       `sk_user_profile`.`f_name`,
       `sk_user_profile`.`m_name`,
       `sk_user_profile`.`l_name`,
       `sk_user_profile`.`address`
FROM `sk_award_nominee`
LEFT JOIN `sk_user` ON `sk_user`.`user_id`=`sk_award_nominee`.`user_id`
LEFT JOIN `sk_user_profile` ON `sk_award_nominee`.`user_id`=`sk_user_profile`.`user_id`
WHERE `sk_award_nominee`.`status` = 1
  AND DATE(approval_date) = '2016-02-22'
ORDER BY `totalUserVoted` DESC,
         `totalRating` DESC

1 个答案:

答案 0 :(得分:0)

这样的东西?

class ProfileViewController: UIViewController {
var user:User?
@IBOutlet weak var userNameLabel: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()
    getUserData { myUser in
        self.userNameLabel.text = myUser.name
        user = myUser
    }

PHP MySQL Order by Two Columns