基本SQL语句

1、插入数据:

insert into 表名(字段1,字段2)values(值1,值2)

2、删除数据:

delete from 表名 where 条件

删除一张表:

drop table 表名

3、修改数据:

update 表名 set 字段=值 where 条件

4、查询数据:

总数:select count(*)from table1 where 范围

去重总数:select count (distinct(字段1) from table1 where 范围(distinct可去重)

求和:select sum (字段1) from table1 where 范围

平均:select avg(字段1) from table1 where 范围

最大:select max(字段1)from table1 where 范围

最小:select min(字段1) from table1 where 范围

排序:select* from table1 where 范围 order by 排序字段名 desc(desc逆序排序。默认是正序排序asc)

5、嵌套查询:

查询重复数据并统计重复数据有多少:select 姓名,count(姓名) from student group by 姓名 having count(姓名)>=2

6、左连接查询:

select * from table1 as a left join table2  as b on a.id=b.id where 条件

7、右连接查询

select * from table1 as a right join table2 as b on a.id=b.id where 条件

8、全连接查询

select * from table1 as a full join table2 as b on a.id =b.id where 条件

9、内连接查询

select * from table1 as a inner join table2 as b on a.id =b.id where 条件

10、分组查询

select * from table group by 字段

11、查询排序

顺序:select * from table order by 字段 asc 

倒序:select * from table order by 字段 desc

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值