mysql - SQL - How to add this custom order for my select query? -


i'm using mysql, , want add custom order select query.

for example i'm having table name a, there column 'a' , 'b'. , can assure 'b' bigger 'a'.

|a|b| |3|4| |1|9| |2|7| |6|9| |8|9| |2|6| |4|8| 

i want select them out , order value c = 5, order rule is:

if c less both , b weight 1.

if c between , b weight 2.

if c bigger both , b weight 3.

and order weight value.

(the order of same weight not need considered here.)

so result should be:

|a|b| |6|9| -> weight 1 |8|9| -> weight 1 |1|9| -> weight 2 |2|6| -> weight 2 |2|7| -> weight 2 |4|8| -> weight 2 |8|9| -> weight 3 

so how write select query?

ps: doesn't have specify weight 1, 2 , 3 in query, weight 'invented' above myself address order rule!

you can use case this:

order case when @c < , @c < b 1               when < @c , @c < b 2               when @c > , @c > b 3          end 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -