你的位置:首页 > 数据库

[数据库]按计算列排序


如果要对计算列排序,可以为计算列指定别名,然后按别名排序。

创建测试用表:

CREATE OR REPLACE VIEW v ASSELECT 3 AS a, 4 AS b FROM DUALUNION ALLSELECT 2 AS a, 3 AS b FROM DUALUNION ALLSELECT 1 AS a, 2 AS b FROM DUAL;SELECT * FROM v;

sql代码如下:

SELECT a, b, a * b AS c FROM v ORDER BY c;

执行结果如下:

由此可见:只要能将数据查询出来,就能根据相应的信息排序。