增删改查

''''''

#建表
# create table t1(
# id int primary key auto_increment,
# name char(12) not null,
# sex enum('male','female') default 'male',
# hobby set('打篮球','玩游戏','吃饭')
# )

#增
# insert into t1 values(1,'大壮','male','打篮球');
# insert into t1 values(2,'李帅','female','打篮球,玩游戏'),(3,'婷','female','吃饭');
# insert into t1 values(4,'bge','male','打篮球,玩游戏');
# insert into t1(name,hobby) values('haha','吃饭'),('拉拉','吃饭,玩游戏,打篮球');
#
# insert into t2 select id,name from t1;
#查



#删
# 清空表:
# delete from t1;
# 会清空表,但是不会清空自增字段的offset(偏移量)值
#
# truncate t1; 自增从o开始
# 会清空表和自增字段的偏移量
#
# 删除某一条数据
# delete from 表 where 条件;
# 先查后删除,有可能删除半张表就没了
# eg:
# delete from t1 where sex = 'male';
#改
# update 表 set 字段=值,字段=值 where 条件

#10个查询 1个增删改
''''''

#建表
# create table t1(
# id int primary key auto_increment,
# name char(12) not null,
# sex enum('male','female') default 'male',
# hobby set('打篮球','玩游戏','吃饭')
# )

#增
# insert into t1 values(1,'大壮','male','打篮球');
# insert into t1 values(2,'李帅','female','打篮球,玩游戏'),(3,'婷','female','吃饭');
# insert into t1 values(4,'bge','male','打篮球,玩游戏');
# insert into t1(name,hobby) values('haha','吃饭'),('拉拉','吃饭,玩游戏,打篮球');
#
# insert into t2 select id,name from t1;
#查



#删
# 清空表:
# delete from t1;
# 会清空表,但是不会清空自增字段的offset(偏移量)值
#
# truncate t1; 自增从o开始
# 会清空表和自增字段的偏移量
#
# 删除某一条数据
# delete from 表 where 条件;
# 先查后删除,有可能删除半张表就没了
# eg:
# delete from t1 where sex = 'male';
#改
# update 表 set 字段=值,字段=值 where 条件

#10个查询 1个增删改
#1.select 语句

#临时重名名

# select 字段 as 新名字,... from 表
#去重


#select distinct 字段 from 表
# select distinct age,sex from employee

#四则运算

# select id,salary*12 as year_salary from employee;

#字符串拼接函数

#concat() concat_ws(拼接符)
#seelct concat(emp_name,':',)

#concat
#concat_ws

#使用判断逻辑
#when then

#where 筛选所有符合条件的行
#比较预算福
#范围
#between ...and....
#in()
#模糊查询
# like
# _

# 分组group by,根据谁分组,可以求这个组的总人数,最大值,最小值,平局值
#求和,但是这个求出来的值只是和分组字段对应,并不和其他任何字段对应
#这个时候查出来的所有其他字段都不生效

'''
每个年龄段
部门
每个部门薪资最高,最低,平均值




'''
# 聚合函数
#count()
#max
#min
#sum
#avg


#having 过滤语句
#在having条件中可以使用聚合函数,在where中不行
#适合筛选某一组数据,而不是某一行数据;
#先分组,再过滤:求平均薪资大于xx的部门,求人数大于xx的性别,求大于xx人的年陵端

#排序 order by
'''
默认是升序 asc
降序 desc
order by age,salary desc
在年龄相同的情况下,薪资从大到小排


'''

#limit
'''
从 m+1项开始,取n项
如果不写m,默认是0
limit n offset m

'''



posted @ 2021-03-03 21:06  苦行僧冬*婷  阅读(45)  评论(0)    收藏  举报