尊龙凯时人生就是博

sqlÖÐorder byµÄ¼ÄÒå

sqlÖÐµÄ order by ×Ó¾äÓÃÓÚ¶ÔÅÌÎÊЧ¹û°´Ö¸¶¨Ã¶¾ÙÐÐÅÅÐò£¬¿ÉÖ¸¶¨ÉýÐò£¨asc£©»ò½µÐò£¨desc£©ÅÅÁУ¬»¹¿ÉÖ¸¶¨¶à¸öÅÅÐòÌõ¼þ¡£Ä¬ÈÏÇéÐÎÏ£¬null ÖµÊÓΪ×î´óÖµ£¬¿ÉʹÓà is null ×Ó¾ä¸ü¸Ä´ËÐÐΪ¡£

SQL ÖÐ ORDER BY µÄ¼ÄÒå

ORDER BY ×Ó¾äÓÃÓÚ¶ÔÅÌÎÊЧ¹ûƾָ֤¶¨Ã¶¾ÙÐÐÅÅÐò¡£Ëü¿ÉÒÔÈÃÄú°´ÉýÐò£¨ÉýÐò£©»ò½µÐò£¨½µÐò£©ÅÅÁÐÊý¾Ý¡£

Óï·¨£º

SELECT * FROM table_name
ORDER BY column_name [ASC | DESC];

µÇ¼ºó¸´ÖÆ

column_name£ºÒªÆ¾Ö¤ÆäÅÅÐòµÄÁС£

ASC£ºÖ¸¶¨ÉýÐòÅÅÐò£¨´Ó×îСµ½×î´ó£©¡£

DESC£ºÖ¸¶¨½µÐòÅÅÐò£¨´Ó×î´óµ½×îС£©¡£

ʾÀý£º

Òª°´ employees ±íÖÐµÄ “salary” ÁÐÉýÐòÅÅÐò£¬¿ÉÒÔʹÓÃÒÔÏÂÅÌÎÊ£º

SELECT * FROM employees
ORDER BY salary ASC;

µÇ¼ºó¸´ÖÆ

Òª°´ “name” ÁнµÐòÅÅÐò£¬¿ÉÒÔʹÓÃÒÔÏÂÅÌÎÊ£º

SELECT * FROM employees
ORDER BY name DESC;

µÇ¼ºó¸´ÖÆ

¶à¸öÅÅÐòÌõ¼þ£º

ORDER BY ×Ó¾ä¿ÉÒÔÖ¸¶¨¶à¸öÅÅÐòÌõ¼þ¡£ÕâЩÌõ¼þ°´Ö¸¶¨Ë³ÐòÓ¦Óá£ÀýÈ磬Ҫ°´ “salary” ÁнµÐò£¬È»ºó°´ “name” ÁÐÉýÐòÅÅÐò£¬¿ÉÒÔʹÓÃÒÔÏÂÅÌÎÊ£º

SELECT * FROM employees
ORDER BY salary DESC, name ASC;

µÇ¼ºó¸´ÖÆ

NULL ÖµµÄÅÅÐò£º

ĬÈÏÇéÐÎÏ£¬NULL ÖµÔÚÅÅÐòÖб»ÊÓΪ×î´óÖµ¡£Òª¸ü¸Ä´ËÐÐΪ£¬¿ÉÒÔʹÓà IS NULL ×Ӿ䣺

SELECT * FROM employees
ORDER BY salary IS NULL DESC, salary ASC;

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄʾÀýÖУ¬NULL Öµ½«±»ÊÓΪ×îСֵ²¢°´½µÐòÅÅÐò¡£

ÒÔÉϾÍÊÇsqlÖÐorder byµÄ¼ÄÒåµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ