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 的名字;

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值