mysql的select查询语句

2018-06-18 00:47:01来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

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)

  

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:数据库索引的使用

下一篇:sql针对某一字段去重,并且保留其他字段