MySQL(二)

全表查询

select * from 表名 where 字段='值' and 字段='值' limit N;

或者or

select * from 表名 where 字段='值' or 字段='值' limit N;

包含in

select * from 表名 where 字段 in ('值','值') limit N;

查询一定数据范围(包含开始结束)between

select * from 表名 where 字段 between ‘值' and ’值' limit N;

不包含not

select * from 表名 where 字段 not in('值','值') limit N;

包含like '值%' %占位

select * from 表名 where 字段 like '值%' limit N;

以什么作中间

 以什么做结尾

以什么开头 rlike '^值'

以什么为结尾 rlike '值$'

别名 as

select count(*) as count from employees;

select count(*) as 别名 from 表名;

ORDER BY 语句用于根据指定的列对结果集进行排序

降序查询 desc

select * from 表名 order by 字段 desc limit 5;

升序排序 asc

select * from 表名 order by 字段 asc limit 5;

求总和

select sum(表项) from 表名;

求平均

select avg(表项) from 表名;

求最大值最小值

select max(表项),min(表项) from 表名 limit 5;

group by 根据一个或多个列对结果集进行分组

查询总数 count(*)/count(1)

select 表项,count(1) as count from 数据库表 group by 表项;

 distinct:去重

select distinct 表项 from 表名 limit N;

过滤 having

select emp_no,avg(salary) as avg from salaries group by emp_no having avg
>140000 order by avg desc;

inner join 内连接,主要是获取两个表中字段匹配关系的表,查询关联字段共同拥有的数据

on 添加约束

select A表字段,A表字段,B表字段,B表字段 from A表名 as s inner join B表名 as b on s.id=b.id;

left join 左连接,获取左表所有信息,获取左表所有数据符合要求的字段数据信息

select * from A表名 as s left join B表名 as b on s.id=b.id;

right join 右连接,获取右表所有信息,获取右表所有数据符合要求的字段数据信息

select * from A表名 as s right join B表名 as b on s.id=b.id;

where  in子查询,in运算符来确定指定列的值是否匹配列表中的值或子查询中的任何值。

select 表名.表项 from 表名 where id in (select id from student where id=1);

多表的数据查询

select * from A表名 inner join B表名 on A表名.id=B表名.id inner join C表名 on B.id=C.pid;

 select 关键字.A表指定表项,关键字.A表指定表项,B表指定表项,关键字.B表指定表项 from A表名 关键字 inner join B表名 关键字 on 关键字.A表可关联指定表项=关键字.B表可关联指定表项 inner join C表名 关键字 on 关键字.B表可关联指定表项=关键字.C表可关联指定表项;

创建索引是指在某个表的一列或多列上建立一个索引,可以提高对表的访问速度。

已有表创建索引 alter table 表名 add index 索引名 索引类型 (列名,列名)

当不再需要索引时,可以使用 DROP INDEX 语句或 ALTER TABLE 语句来对索引进行删除。

drop index 索引名 on 表名;

小问题

# !/usr/bin/env python
# -*- coding:utf-8 -*-

"""
1、查询端口的命令
losf -i:端口
2、查询进程的命令
ps
3、如果一个日志文件一直在写入新的内容,怎么查看文件最后的内容
tail -f log.txt
获取go python和测试工程师
"""

lists = {"status": 0, "msg": "ok", "datas": [{"language": ["Go", {"index": ["python", {"work": "测试工程师"}]}]}]}
for item in lists["datas"]:
    print(item["language"][0])
    print(item["language"][1]["index"][0])
    print(item["language"][1]["index"][1]["work"])

 

posted @ 2021-08-02 10:35  星德川  阅读(67)  评论(0)    收藏  举报