Java面试题总汇(二)之数据库SQL语句

版权声明:嫣子的播客 https://blog.csdn.net/weixin_44067762/article/details/85782693

=-=-=-=-=-此 处 分割线=-=-=-=-=-
biubiubiu~觉得不错可以继续阅读其他博客哟
此播客如有侵权请联系我改正哦,日常在线,如不在线未及时回复请包涵等待
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

*是选取所有列

多个列名用逗号(,)隔开


创建数据库:

create database 数据库名

删除数据库:

drop database 数据库名

创建新表:

create table 表名(
    字段1 (长度)[约束],
    字段2 (长度)[约束],
    字段3 (长度)[约束],
    ...
)

查看表数据:

desc 表名

更改表名:

rename table 表名 to 新表名

修改/更新 表信息:

update 表名 set 条件

删除表信息1:

(删除表信息,但是自增id还占着位置不会删除)
delete from 表名 where 条件

(删除表信息,当再次添加数据回填补)
truncate tale 表名

去掉重复值:

select distinct 列名 form 表名

升降序:

select * from 表名 order by 列名 decs/asc

分页查询:

select * from 表名 limit 0,5 

limit分页公式(第几页-1×每页显示多少页=第几页的索引)

第2页显示5条数据
select * from tb_user limit 5,5


分组查询:

select * form 表名 group by 列名

修改表数据:

update 表名 set 列名=新值 where 列名=某值

搜索模糊范围:

select * from 表名 where 列名 like ('%需要查找的值%')

查询多个值:

select * from 表名 where 列名 in('值1 ','值2 ')

在某某范围之间查询:

select * from 表名  where 列名 between '值1' and '值2'

取别名:

select 列名1 as 列名1的别名 ,列名2 as 列名2的别名 form 表名

求平均值:

select avg(*) from 表名

求和:

select sum(*) from 表名

求总数目:

select count(*) form  表名

=-=-=-=-=-此 处 分割线=-=-=-=-=-
biubiubiu~觉得不错可以继续阅读其他博客哟
此播客如有侵权请联系我改正哦,日常在线,如不在线未及时回复请包涵等待
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

猜你喜欢

转载自blog.csdn.net/weixin_44067762/article/details/85782693