Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql order by calculated column

CREATE TABLE a(a INT, b INT);

INSERT INTO a VALUES (1, 1);
INSERT INTO a VALUES (1, 2);
INSERT INTO a VALUES (1, 3);
INSERT INTO a VALUES (1, 4);
INSERT INTO a VALUES (1, 5);
INSERT INTO a VALUES (1, 6);
INSERT INTO a VALUES (2, 1);
INSERT INTO a VALUES (2, 2);
INSERT INTO a VALUES (2, 3);
INSERT INTO a VALUES (2, 4);
INSERT INTO a VALUES (2, 5);
INSERT INTO a VALUES (2, 6);

SELECT a.a, a.b, (a/b) FROM a ORDER BY (a/b);

+------+------+--------+
| a    | b    | (a/b)  |
+------+------+--------+
|    1 |    6 | 0.1667 | 
|    1 |    5 | 0.2000 | 
|    1 |    4 | 0.2500 | 
|    2 |    6 | 0.3333 | 
|    1 |    3 | 0.3333 | 
|    2 |    5 | 0.4000 | 
|    1 |    2 | 0.5000 | 
|    2 |    4 | 0.5000 | 
|    2 |    3 | 0.6667 | 
|    2 |    2 | 1.0000 | 
|    1 |    1 | 1.0000 | 
|    2 |    1 | 2.0000 | 
+------+------+--------+
Comment

PREVIOUS NEXT
Code Example
Sql :: oracle temp tablespace size 
Sql :: how to open database 
Sql :: delete in sql server 
Sql :: psotgres multiple values 
Sql :: oracle sql first day of quarter 
Sql :: sql select data from one database and insert into a different database 
Sql :: fatal database postgres does not exist 
Sql :: adonisjs ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client 
Sql :: mask data in sql 
Sql :: IDE1006 (Naming rule violation) error problem 
Sql :: how to subquey to do not load in live database in 
Csharp :: unity next scene 
Csharp :: unity scene change 
Csharp :: c# random float between two numbers 
Csharp :: c# gzip byte array 
Csharp :: quit button unity 
Csharp :: use enter key unity 
Csharp :: c# open folder in explorer 
Csharp :: check connection c# 
Csharp :: c# write all bytes to a file 
Csharp :: unity enable gameobject 
Csharp :: get scene name unity 
Csharp :: c# executable directory 
Csharp :: 3(x-4)-2(3x+4)=4(3-x)+5x+4 
Csharp :: Csharp convert string to double 
Csharp :: how to create directory folder in c# 
Csharp :: get random point in collider unity 
Csharp :: get key unity 
Csharp :: unity get project file directory 
Csharp :: OnCollision update unity 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =