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)
    

      

  • 相关阅读:
    检测mysq组复制的脚本
    centos7安装NFS
    mysql组复制安装
    springboot+VUE(一)
    redis集群配置
    codevs 3139 栈练习3
    codevs 3138 栈练习2
    codevs 2622 数字序列
    codevs 1054 电梯
    codevs 1507 酒厂选址
  • 原文地址:https://www.cnblogs.com/orna/p/8298931.html
Copyright © 2011-2022 走看看