My SQL 命令行知识点总结(一)

       今日再一次的翻看了数据库的书,想到了自己刚刚入门的时候的麻烦,特来写一篇入门的命令行总结。对自己是一个总结,当然了希望可以帮到哪怕一个人。

今日着重介绍搜索类型的命令行。

my sql 数据库    >各类子数据库    >每个库还有表

当我们打开数据库的时候,可以先查看所有的  库 

show databases;

如果有自己要使用的表,可以直接 use table;(table指的是某一张表)

1、展示该表的所有内容

select * from table;

2、展示某一列的内容

select  id from table;

3、展示多列的内容

select id,name from table;

4、展示指定行数的内容

select id,name from table limit 5;

6、指定多列内容且是从第几行开始

select id,name from limit 5 offset 2;

上述的内容的意思是从第二行(my sql 的第一行为0)开始的五行内容

7、展示类别的内容(如每个年龄仅仅展示一个,个人感觉应运场景就是展示多少类别)order

select distinct sex from table;

8、升序,降序

select id ,age from table order by age;         --升序(默认升序)

select id ,age from table  order by age desc;   -- 降序

select id ,age from table order by age , id desc;   --整体的趋势为按年龄降序,年龄相同的情况下降序

9、过滤语句

select id ,age from table where age >18;      --要求年龄大于18  

select id ,age from table where between 18 and 60;  -- 要求年龄大于18 以及小于60

10、高级过滤

select id,age from table where age >18 and age <60;  --与上诉的between 效果一样

select id age from table where age >18 or id <20;    --可以理解为或的意思

11通配符的运用(其实可以理解为模糊搜索)

select id,age from table where name like '%w%';   -- 查看名字中带有 w 的名字

select id,age from table where name like 'w%';

select id,age from table where name like '%w';

12、下划线的“_”通配符

select id,age from table where name like '__w' -- 查看名字中第三个字符为 w 的名字;

                                                                                --因为前看有右两个下划线“_”

猜你喜欢

转载自blog.csdn.net/qq_43238599/article/details/88383541
今日推荐