Search
 
SCRIPT & CODE EXAMPLE
 

SQL

SQL sort on a calculation

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 :: SQL Creating a Procedure 
Sql :: in condition in sql 
Sql :: max in postgresql 
Sql :: multiple values insert in sql 
Sql :: insert into table with only identity column 
Sql :: SQL SERVER microsoft How to Add Column at Specific Location in Table 
Sql :: parsing float to int in mysql 
Sql :: sql oracle take only last results 
Sql :: sql into vs insert into 
Sql :: xamarin sql lite create table if not exist 
Sql :: add column in table in sql 
Csharp :: how to lock and hide a cursor unity 
Csharp :: unity string split 
Csharp :: unity how to change max fps 
Csharp :: asp.net validate web.config 
Csharp :: how to detect mouse click in c# 
Csharp :: check if gameobject is active 
Csharp :: c# sleep 1 second 
Csharp :: c# preprocessor if not 
Csharp :: unity createassetmenu 
Csharp :: unity how to copy something to the clipboard 
Csharp :: urlreferrer in asp.net core 
Csharp :: usermanager change password without current password 
Csharp :: convert timestamp to datetime c# code 
Csharp :: c# convert string to double 
Csharp :: delete null elements array c# 
Csharp :: unity spawn object at position 
Csharp :: get datacontext of parent wpf 
Csharp :: how to split and get last index values in c# 
Csharp :: There is already a virtual axis named Horizontal registered. unity 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =