美文网首页
mysql order by 排序

mysql order by 排序

作者: klisly | 来源:发表于2017-02-07 15:39 被阅读51次

    1、使用order by 排序:ASC\DES(升序\降序,默认升序)

    题目:查询students表sex="m"的字段显示id,name,age列并按降序排列

    mysql> select id,name ,age from students where sex = "m" order by  age  DESC;

    +----+---------+------+

    | id | name    | age  |

    +----+---------+------+

    |  5 | wendy   |   20 |

    |  6 | ton     |   20 |

    |  7 | liy     |   18 |

    |  2 | hathway |   15 |

    +----+---------+------+

    4 rows in set (0.00 sec)

    2、题目:查询students表sex="m"的字段显示id,name,age列并按升序排列

    mysql> select id,name ,age from students where sex = "m" order by  age  ASC;

    +----+---------+------+

    | id | name    | age  |

    +----+---------+------+

    |  2 | hathway |   15 |

    |  7 | liy     |   18 |

    |  5 | wendy   |   20 |

    |  6 | ton     |   20 |

    +----+---------+------+

    4 rows in set (0.01 sec)

    相关文章

      网友评论

          本文标题:mysql order by 排序

          本文链接:https://www.haomeiwen.com/subject/rkqmittx.html