#创建学员成绩视图
create view v_score
as
select
scoreId,
stuName,
score,
if(isIn,'正常','缺考') isIn,
if(level,'正常',concat('补考',(level-1)))
from
score S
inner join
student U
on
S.stuId = U.stuId
inner join
subject J
on
s.SubjectId = J.subjectId;
#测试concat用法
select '1'+1;
select 'a'+1;
select concat('a',1);
# 修改部分学员的考试状态
update score set level=2 where stuId%11=0;
# 分组 group_cat(col)
select
provinceId,cityId,group_concat(countyId)
from
student
group by
provinceId,cityId;
# 字符串函数+模糊查询
select
*
from
student
where
stuName
like
concat('张','%');
#多字段分组
select
provinceId,cityId,group_concat(countyId)
from
student
group by
provinceId,cityId;
************************************************************************
#查询索引 (表分区)
show index from student;
#删除索引
drop index ix_name on table_name;
# 查库容量
select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),' MB') as data_size,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables
group by TABLE_SCHEMA
order by data_length desc;
# 查表容量
select TABLE_NAME, concat(truncate(data_length/1024/1024,2),' MB') as data_size,
concat(truncate(index_length/1024/1024,2),' MB') as index_size
from information_schema.tables where TABLE_SCHEMA = 'kh69'
group by TABLE_NAME
order by data_length desc;