创建表:
create table sheet(id int(3),name VARCHAR(10),age int(10))
create table clazz(cid int(8),sid int(3),cname varchar(10));
删除表:
drop table sheet
drop table clazz
插入表数据
insert into sheet values(1,'test',20);
insert into sheet values(2,'xu',30);
insert into sheet values(3,'da',40);
insert into sheet values(4,'go',33);
insert into sheet values(5,'meng',20);
insert into clazz values(1,3,'1班');
insert into clazz values(2,2,'1班');
insert into clazz values(3,4,'1班');
insert into sheet(age) value(33);
查看表内容
select * from sheet
select * from clazz
按条件删除数据
delete from sheet where age=33
根据条件修改数据
update sheet set age=11 where name='test'
按id逆序排列
SELECT * from sheet order by id desc;
按age分组
select sum(id) from sheet GROUP BY age;
age求和
SELECT SUM(age) from sheet
age求平均数
select avg(age) from sheet
age最大值/最小值
select max(age) from sheet
select min(age) from sheet
联合查询
select * from sheet s,clazz c where s.id=c.sid
左查询
select * from sheet s left join clazz c on s.id=c.sid
右查询
select * from sheet s right join clazz c on s.id=c.sid
SQl常用语句
最新推荐文章于 2024-08-16 21:30:01 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)