sonalkr132
sonalkr132

Reputation: 1037

Order on basis of multiple columns

Suppose I have table project which has following fields:

I want to sort project on basis of all the fields, however each field has different precedence. A project with higher issue should be higher up even if it has lesser number of comments or followers. Assume order of precedence to be: issue > followers > comments > created_at

I can't use something like:

Select * from Projects ORDER BY Issue, Followers, Comments, Created_at

This would first order by issues and then solve conflicts on basis of followers and so on. For ex: I would want a project with 5 issues and 10 comments to be placed lower than one with 3 issues but 50 comments.

I guess I would need to use some multiplicative factor to scale everything in proportion. However, I can't figure out details.

Assume: 1 issue = 2 followers = 4 comments = 1 week old created at time

Upvotes: 0

Views: 58

Answers (1)

jarlh
jarlh

Reputation: 44766

Something like this perhaps?

Select * from Projects
ORDER BY Issue * 5 + Followers * 3 + Comments DESC, Created_at

Upvotes: 3

Related Questions