mysql学习(五)数据查询

查询某个字段的确定值情况下的数据


MariaDB [istester]> select * from istester where id='1';
+----+-------+------+-------+------------+---------+-------+
| id | uname | sex  | birth | department | address | idoxu |
+----+-------+------+-------+------------+---------+-------+
|  1 | idoxu | NULL |  NULL | NULL       | NULL    | 2020  |
+----+-------+------+-------+------------+---------+-------+
1 row in set (0.00 sec)

MariaDB [istester]> select *from idoxu where grade='100';
+----+--------+--------+----------+-------+
| id | stu_id | c_name | istester | grade |
+----+--------+--------+----------+-------+
|  5 |     12 | lin    | NULL     |   100 |
+----+--------+--------+----------+-------+
1 row in set (0.00 sec)

包含某个字符

MariaDB [istester]> select * from istester where id like '%1%';
+----+--------+------+-------+------------+---------+-------+
| id | uname  | sex  | birth | department | address | idoxu |
+----+--------+------+-------+------------+---------+-------+
|  1 | idoxu  | NULL |  NULL | NULL       | NULL    | 2020  |
| 11 | idoxu3 | 1    |  NULL | NULL       | NULL    | NULL  |
| 12 | idoxu4 | 2    |  NULL | NULL       | NULL    | NULL  |
| 13 | idoxu5 | 1    |  NULL | NULL       | NULL    | NULL  |
| 14 | idoxu6 | 2    |  NULL | NULL       | NULL    | NULL  |
+----+--------+------+-------+------------+---------+-------+
5 rows in set (0.00 sec)

升序降序排序


MariaDB [istester]> select * from istester where id like '%1%' order by id;
+----+--------+------+-------+------------+---------+-------+
| id | uname  | sex  | birth | department | address | idoxu |
+----+--------+------+-------+------------+---------+-------+
|  1 | idoxu  | NULL |  NULL | NULL       | NULL    | 2020  |
| 11 | idoxu3 | 1    |  NULL | NULL       | NULL    | NULL  |
| 12 | idoxu4 | 2    |  NULL | NULL       | NULL    | NULL  |
| 13 | idoxu5 | 1    |  NULL | NULL       | NULL    | NULL  |
| 14 | idoxu6 | 2    |  NULL | NULL       | NULL    | NULL  |
+----+--------+------+-------+------------+---------+-------+
MariaDB [istester]> select * from istester where id like '%1%' order by id DESC                                                               ;
+----+--------+------+-------+------------+---------+-------+
| id | uname  | sex  | birth | department | address | idoxu |
+----+--------+------+-------+------------+---------+-------+
| 14 | idoxu6 | 2    |  NULL | NULL       | NULL    | NULL  |
| 13 | idoxu5 | 1    |  NULL | NULL       | NULL    | NULL  |
| 12 | idoxu4 | 2    |  NULL | NULL       | NULL    | NULL  |
| 11 | idoxu3 | 1    |  NULL | NULL       | NULL    | NULL  |
|  1 | idoxu  | NULL |  NULL | NULL       | NULL    | 2020  |
+----+--------+------+-------+------------+---------+-------+

MariaDB [istester]> select * from istester where id like '%1%' order by id DESC                                                               limit 3;
+----+--------+------+-------+------------+---------+-------+
| id | uname  | sex  | birth | department | address | idoxu |
+----+--------+------+-------+------------+---------+-------+
| 14 | idoxu6 | 2    |  NULL | NULL       | NULL    | NULL  |
| 13 | idoxu5 | 1    |  NULL | NULL       | NULL    | NULL  |
| 12 | idoxu4 | 2    |  NULL | NULL       | NULL    | NULL  |
+----+--------+------+-------+------------+---------+-------+

最大值最小值


MariaDB [istester]> select grade,c_name from idoxu where grade in (select max(g                                                              rade) from idoxu);
+-------+--------+
| grade | c_name |
+-------+--------+
|   100 | lin    |
+-------+--------+
1 row in set (0.01 sec)

MariaDB [istester]> select grade,c_name from idoxu where grade in (select min(g                                                              rade) from idoxu);
+-------+----------+
| grade | c_name   |
+-------+----------+
|    20 | istester |
+-------+----------+
1 row in set (0.00 sec)

你可能感兴趣的:(mysql学习(五)数据查询)