SQL常用命令--代码规范comment

# 建表

drop database if exists school;
create database school default charset utf8;
use school;
create table tb_college
(
collid int auto_increament comment '编号',
collname varchar(50) not null comment '姓名',
collintro varchar(50) default '' comment '介绍',
primary key (collid)
);
create table tb_student
(
stuid int not null comment '',
stuname varchar(20) not null comment '',
collid int not null comment '',
...
primary key(stuid),
foreign key(collid) references tb_college(collid),
unique(stuid)
);

---------------------------------------------------------------------------------------------

 

# 查询

select distinct seldate from tb_record;
select stuname as 姓名,datediff(curdate(),stubirth) dev 365 as 年龄 from ... where ...;
select avg(score) fromn tb_record where stuid = 1001;
select avg(score) as 平均分 fromn tb_record group by stuid having 平均分 >= 90;
select stuname from tb_student t1,tb_course t2 where stuid = sid and couid = cid; --多表查询
select stuname from tb_student inner join tb_record on stuid = sid; --此处on

----------------------------------------------------------------------------------------------

posted @ 2021-03-01 23:19  沈一愣  阅读(647)  评论(0编辑  收藏  举报