Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8610869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:13:47+00:00 2026-06-12T04:13:47+00:00

Let’s assume a users table like: age | popularity —————— 16 | 2 23

  • 0

Let’s assume a users table like:

 age  | popularity
------------------
  16  |     2
  23  |     5
  17  |     2
  16  |     3
 ...  |    ...
 ...  |    ...

I want to select rows with smaller age and bigger popularity. But not to choose the one over the other.

With:

SELECT *
FROM `users`
ORDER BY `age` ASC, `popularity` DESC

We will have the younger users on top and the users with the same age would be ordered by popularity among themselves.

And with:

SELECT *
FROM `users`
ORDER BY `popularity` DESC, `age` ASC

We will have the most popular users on top and the users with the same popularity ordered by age among themselves.

But I do not want to choose the one sorting over the other. I want to mix them up.

How do I achieve sorting with 60% based on popularity and 40% based on age?

Is there a general-purpose solution for such sorting? Is a custom function the only option?

UPDATE: Sample desired results

 age  | popularity
------------------
  16  |     8
  15  |     2
  23  |     5
  29  |    10
  16  |     3
  16  |     2
  17  |     2

So if a user is very young she should be higher even with smaller popularity. If a user is quite popular she should be higher even if she is older.

The most young and most popular should be always on top. The most old and the least popular should be always on the bottom.

I am looking for a general-purpose solution, not just for numbers, but for dates, strings and so on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:13:49+00:00Added an answer on June 12, 2026 at 4:13 am
    select *, priority*0.6+age*0.4 as sortkey from ... order by sortkey.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have thousands of users and I want to make the passwords
Let's assume I want to deserialize this (I've removed the namespaces to make things
Let assume that I have scaled Heroku application to 1 worker process, but how
Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let's say I have a table with a Color column. Color can have various
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I can call a method like this: core::get() . What is the
Let's assume that we are building a high traffic site that will be used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.