MySQL ORDER BY field1, field2 DESC 和 ORDER BY field1 DESC, field2 DESC 的区别

2024-12-18 杜世伟 Mysql

主要区别总结
ORDER BY field1, field2 DESC:
field1 升序排序(默认)。

当 field1 值相同时,按 field2 降序排序。


ORDER BY field1 DESC, field2 DESC:
field1 降序排序。
当 field1 值相同时,按 field2 降序排序。
排序方向的指定顺序会显著影响结果,因此在写 SQL 时,需要明确每个字段的排序优先级和方向。

阅读全文>>

标签: mysql desc order

评论(0) 浏览(809)

查看mysql表结构信息

2013-7-18 杜世伟 Mysql

一、简单描述表结构,字段类型
desc tabl_name; describe columns
显示表结构,字段类型,主键,是否为空等属性,但不显示外键和字段的注释。
二,查看表生成的DDL
show create table 表名;
这个命令虽然显示起来不是太容易看, 这个不是问题可以用\G来结尾,使得结果容易阅读;该命令把创建表的DDL显示出来,于是表结构、类型,外键,备注全部显示出来了。我比较喜欢这个命令:输入简单,显示结果全面。
三,查询表中列的注释信息
use  information_schema
select * from columns where  table_name = '表名' ;
四、查看表的注释
select table_name,table_comment frominformation_schema.tables  where table_schema = 'db' and table_name='表名'
五,只查询列名和注释
select  column_name, column_comment from information_schema.columnswhere table_schema ='db'  and table_name = '表名' ;

标签: linux mysql select desc use show

评论(0) 浏览(5081)

Powered by emlog 沪ICP备2023034538号-1