zoukankan      html  css  js  c++  java
  • mysql的select查询语句

    1.简单查询

    mysql> select * from students;
    +------------+----------+------+------+
    | id         | sname    | sex  | tid  |
    +------------+----------+------+------+
    | 0000000001 | orna     | 男   | NULL |
    | 0000000002 | luscy    | 女   | NULL |
    | 0000000003 | wangwu   | 男   | NULL |
    | 0000000020 | zhangsan | 男   | NULL |
    +------------+----------+------+------+
    4 rows in set (0.00 sec)
    
    
    mysql> select id,ifnull(sname,'无') name from students;
    +------------+----------+
    | id         | name     |
    +------------+----------+
    | 0000000001 | orna     |
    | 0000000002 | luscy    |
    | 0000000003 | wangwu   |
    | 0000000020 | zhangsan |
    +------------+----------+
    4 rows in set (0.00 sec)

       mysql> select * from students where sname like 'o%';
       +------------+-------+------+------+
       | id | sname | sex | tid |
      +------------+-------+------+------+
      | 0000000001 | orna | 男 | NULL |
      +------------+-------+------+------+
      1 row in set (0.00 sec)

    2.排序

    mysql> select * from students order by sname desc;
    +------------+----------+------+------+
    | id         | sname    | sex  | tid  |
    +------------+----------+------+------+
    | 0000000020 | zhangsan | 男   | NULL |
    | 0000000003 | wangwu   | 男   | NULL |
    | 0000000001 | orna     | 男   | NULL |
    | 0000000002 | luscy    | 女   | NULL |
    +------------+----------+------+------+
    4 rows in set (0.00 sec)
    
    mysql> select * from students order by sname desc limit 1;
    +------------+----------+------+------+
    | id         | sname    | sex  | tid  |
    +------------+----------+------+------+
    | 0000000020 | zhangsan | 男   | NULL |
    +------------+----------+------+------+
    1 row in set (0.00 sec)
    

      

  • 相关阅读:
    WinForm容器内控件批量效验是否同意为空?设置是否仅仅读?设置是否可用等方法分享
    EF的CRUD
    SICP 习题 (1.41)解题总结
    陈光标挽救纽约穷人背后有何玄机?
    poj 1276 Cash Machine(多重背包)
    vue的生命周期
    vue mounted组件的使用
    babel-polyfill的几种使用方式
    可拖拽排序的vue组件
    import、export 和 export default
  • 原文地址:https://www.cnblogs.com/orna/p/8298931.html
Copyright © 2011-2022 走看看