网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 服务器与数据库 > MySQL
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 49.87.51.222
Old 2015-01-14, 10:22 PM
Cedar Brook Cedar Brook is offline
初级会员
 
Join Date: 2008-08-23
Posts: 2
Cedar Brook 现在声名狼藉
Default MySQL教程:Order By用法

先按照下面的表结构创建mysql_order_by_test数据表,我们用实例一点一点告诉你,MySQL order by的用法。

ORDER BY uid ASC

按照uid正序查询数据,也就是按照uid从小到大排列

ORDER BY uid DESC

按照uid逆序查询数据,也就是按照uid从大到小排列

我们来看

SELECT * FROM mysql_order_by_test ORDER BY uid ASC

这条语句是按照uid正序查询数据,也就是按照uid从小到大排列

返回的结果就是:

1  张三  1

2 李四 2

3 王二麻子 1

我们来看

SELECT * FROM mysql_order_by_test ORDER BY uid DESC

这条语句是按照uid逆序查询数据,也就是按照uid从大到小排列

返回的结果是:

3  王二麻子  1

2 李四 2

1 张三 1

SQL创建代码:

CREATE TABLE IF NOT EXISTS mysql_order_by_test (
 uid int(10) NOT NULL AUTO_INCREMENT,
 name char(80) NOT NULL,
 sex tinyint(1) NOT NULL,
 KEY uid (uid)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
  
INSERT INTO mysql_order_by_test (uid, name, sex) VALUES(1, '张三', 1);
INSERT INTO mysql_order_by_test (uid, name, sex) VALUES(2, '李四', 2);
INSERT INTO mysql_order_by_test (uid, name, sex) VALUES(3, '王二麻子', 1);
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 03:47 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.