sqlÖнµÐòÔõôд
sql ÖпÉͨ¹ýʹÓà desc Òªº¦×ÖʵÏÖ½µÐòÅÅÐò¡£Óï·¨£ºselect column_name(s) from table_name order by column_name desc;ÀýÈ磬°´ salary ÁнµÐòÅÅÁÐÔ±¹¤£ºselect name, salary from employees order by salary desc¡£
SQL ÖÐʵÏÖ½µÐòÅÅÐò
ÔÚ SQL ÖУ¬ÊµÏÖ½µÐòÅÅÐòµÄÒªÁìºÜÊǼòÆÓ£¬¿ÉÒÔͨ¹ýʹÓÃÒªº¦×Ö DESC¡£
Óï·¨£º
SELECT column_name(s) FROM table_name ORDER BY column_name DESC;
µÇ¼ºó¸´ÖÆ
ʾÀý£º
¼ÙÉèÎÒÃÇÓÐÈçϱí¸ñ£º
CREATE TABLE employees ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, salary INT NOT NULL, PRIMARY KEY (id) );
µÇ¼ºó¸´ÖÆ
ÒÔÏÂÅÌÎʽ«°´ salary ÁÐÒÔ½µÐòÅÅÁзµ»ØËùÓÐÔ±¹¤£º
SELECT name, salary FROM employees ORDER BY salary DESC;
µÇ¼ºó¸´ÖÆ
×¢ÖØÊÂÏ
DESC Òªº¦×ÖÖ»ÄÜÓÃÓÚ ORDER BY ×Ó¾äÖС£
¿ÉÒÔ¶Ô¶à¸öö¾ÙÐнµÐòÅÅÐò£¬Ö»Ð轫ÁÐÃûÓöººÅÍÑÀ룬ȻºóÔÚÿ¸öÁÐÃûºó¸½¼Ó DESC¡£ÀýÈ磺
SELECT name, salary FROM employees ORDER BY salary DESC, name DESC;
µÇ¼ºó¸´ÖÆ
Õ⽫°´½µÐòÅÅÁÐµÄ salary ÁжÔЧ¹ûÅÅÐò£¬ÈôÊÇ salary ÏàµÈ£¬Ôò°´½µÐòÅÅÁÐµÄ name ÁжÔЧ¹û¾ÙÐÐÅÅÐò¡£
ÒÔÉϾÍÊÇsqlÖнµÐòÔõôдµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡