如何在MySQL中更改项目顺序?
要更改MySQL中项目的顺序,请使用ORDERBY别名。让我们首先创建一个表-
mysql> create table DemoTable653 (Product1Amount int,Product2Amount int);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable653 values(400,250); mysql> insert into DemoTable653 values(500,300); mysql> insert into DemoTable653 values(40,400); mysql> insert into DemoTable653 values(200,450); mysql> insert into DemoTable653 values(50,20);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable653;
这将产生以下输出-
+----------------+----------------+ | Product1Amount | Product2Amount | +----------------+----------------+ | 400 | 250 | | 500 | 300 | | 40 | 400 | | 200 | 450 | | 50 | 20 | +----------------+----------------+ 5 rows in set (0.00 sec)
以下是更改项目顺序并显示差异的查询-
mysql> select Product1Amount,Product2Amount,(Product1Amount-Product2Amount) as ProductAmountDifference from DemoTable653 order by ProductAmountDifference;
这将产生以下输出-
+----------------+----------------+-------------------------+ | Product1Amount | Product2Amount | ProductAmountDifference | +----------------+----------------+-------------------------+ | 40 | 400 | -360 | | 200 | 450 | -250 | | 50 | 20 | 30 | | 400 | 250 | 150 | | 500 | 300 | 200 | +----------------+----------------+-------------------------+ 5 rows in set (0.29 sec)
热门推荐
10 生日祝福语男孩 简短独特
11 员工对同事祝福语简短
12 叶海燕老师祝福语简短
13 朋友祝福语两字简短
14 冬季祝福语大全 简短的
15 生日祝福语古语简短创意
16 年后祝福语简短走心
17 新娘对伴娘祝福语简短
18 项目建设春节祝福语简短