温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

简单弄懂MySQL数据库基础知识

发布时间:2020-05-08 15:34:23 来源:三月 阅读:179 作者:三月 栏目:MySQL数据库

本文主要给大家简单讲讲MySQL数据库基础知识,相关专业术语大家可以上网查查或者找一些相关书籍补充一下,这里就不涉猎了,我们就直奔主题吧,希望MySQL数据库基础知识这篇文章可以给大家带来一些实际帮助。

SQL语句实战——DML语句(重点)

选择:select * from table1 where 范围

插入:insert into table1(filed1,filed2)values (filed1,filed2)

解释:filed1,filed2 字段名;filed1,filed2字段值

删除:delete from table1 where 范围

更新:update table1 set field1=value1 where 范围

查找:select * from table1where filed1 like ‘%value1%’ 

 解释:查找包含value1的模糊匹配

如果查找以value1开头,则用‘value1%’;

如果查找以value1结尾:则用‘%value1’;

排序:select * from table1 order by filed1,filed2[desc]

解释:[desc]倒叙  [asc]正序

总数:select count(*) as totalcount from table1

求和:select sum(field1) as sumvalue from table1

平均:select avg(field1) as avgvalue from table1

最大:select max(field1) as maxvalue from table1

最小:select min(field1) as minvalue from table1


实战练习:

1) 插入

对persion_info插入四条数据:

语句:(person_id是自增长的,所以不用写)

insert into person_info(name,country,salary)

values ( '小赵 ', 'China',1200.01),

('小钱 ', '上海 ',1600.32),

( '小孙 ', '广州 ',2000.40),

( '小李 ', '珠海 ',1670.88);

执行结果:

简单弄懂MySQL数据库基础知识

2) 更新:

如果想把小赵的country字段换成北京,则执行语句:

update person_info set country = '北京' where name = '小赵';

执行后的结果如下:

简单弄懂MySQL数据库基础知识


3) 排序

对name进行order by排序

语句:select * from person_info order by name desc;

运行结果:


简单弄懂MySQL数据库基础知识

4) 查找

查找包含“赵”的模糊匹配数据,语句“”

Select * from person_info where name like ‘%赵%’;

运行结果:

简单弄懂MySQL数据库基础知识

5) 总数

求person_info表里的数据总条数

语句:Select count(*) as totalcount from person_info;

执行结果:

简单弄懂MySQL数据库基础知识

可见结果是4,同时字段名为totalcount。

 

6) 求和

语句:select sum(salary) as sumvalue from person_info;

执行结果:

简单弄懂MySQL数据库基础知识

MySQL数据库基础知识就先给大家讲到这里,对于其它相关问题大家想要了解的可以持续关注我们的行业资讯。我们的板块内容每天都会捕捉一些行业新闻及专业知识分享给大家的。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI