当前位置: 首页 > news >正文

政府网站群云防护建设方案网盘资源搜索神器

政府网站群云防护建设方案,网盘资源搜索神器,17网做网站,基础型网站函数 是指一段可以直接被另一段程序调用的程序或代码。 也就意味着,这一段程序或代码在MySQL中已经给我们提供了,我们要做的就是在合适的业务场景调用对应的函数完成对应的业务需求即可。 那么,函数到底在哪儿使用呢?我们先来看两个场景&…

函数 是指一段可以直接被另一段程序调用的程序或代码。 也就意味着,这一段程序或代码在MySQL中已经给我们提供了,我们要做的就是在合适的业务场景调用对应的函数完成对应的业务需求即可。 那么,函数到底在哪儿使用呢?

我们先来看两个场景:

1). 在企业的OA或其他的人力系统中,经常会提供的有这样一个功能,每一个员工登录上来之后都能够看到当前员工入职的天数。而在数据库中,存储的都是入职日期,如2000-11-12,那如果快速计算出天数呢?

2). 在做报表这类的业务需求中,我们要展示出学员的分数等级分布。而在数据库中,存储的是学生的分数值,如98/75,如何快速判定分数的等级呢?其实,上述的这一类的需求呢,我们通过MySQL中的函数都可以很方便的实现。

MySQL中的函数主要分为以下四类:字符串函数、数值函数、日期函数、流程函数。

字符串函数

MySQL中内置了很多字符串函数,常用的几个如下:

演示如下:

A. concat : 字符串拼接

select concat('Hello',' MySQL');

B. lower : 全部转小写

select lower('Hello');

C. upper : 全部转大写

select upper('Hello');

D. lpad : 左填充

select lpad('01',5,'-');

E. rpad : 右填充

select rpad('01',5,'-');

F. trim : 去除空格

select trim(' Hello MySQL ');

G. substring : 截取子字符串

select substring('Hello MySQL',1,5);

案例:

由于业务需求变更,企业员工的工号,统一为5位数,目前不足5位数的全部在前面补0。比如: 1号员工的工号应该为00001。

update emp set workno =lpad(workno,5,'0');

处理完毕后, 具体的数据为:

数值函数

常见的数值函数如下:

演示如下:

A. ceil:向上取整

select ceil(1.1);

B. floor:向下取整

select floor(1.9);

C. mod:取模

select mod(7,4);1

D. rand:获取随机数

select rand();

E. round:四舍五入

select round(2.344,2);

案例:

通过数据库的函数,生成一个六位数的随机验证码。

思路: 获取随机数可以通过rand()函数,但是获取出来的随机数是在0-1之间的,所以可以在其基础上乘以1000000,然后舍弃小数部分,如果长度不足6位,补0。

select lpad(round(rand()*1000000,0),6,'0');

日期函数

常见的日期函数如下:

演示如下:

A. curdate:当前日期

select curdate();

B. curtime:当前时间

select curtime();

C. now:当前日期和时间

select now();

D. YEAR , MONTH , DAY:当前年、月、日

select YEAR(now()); 
select MONTH(now()); 
select DAY(now());

E. date_add:增加指定的时间间隔

select date_add(now(), INTERVAL 70 YEAR );

F. datediff:获取两个日期相差的天数

select datediff('2021-10-01','2021-12-01');

案例:

查询所有员工的入职天数,并根据入职天数倒序排序。入职天数,就是通过当前日期 - 入职日期,所以需要使用datediff函数来完成。

select name,datediff(curdate(), entrydate) as 'entrydays' from emp order by 
entrydays desc;

流程函数

流程函数也是很常用的一类函数,可以在SQL语句中实现条件筛选,从而提高语句的效率。

演示如下:

A. if

select if(false,'Ok','Error');

B. ifnull

select ifnull('Ok','Default'); 
select ifnull('','Default'); 
select ifnull(null,'Default');

C. case when then else end

需求: 查询emp表的员工姓名和工作地址 (北京/上海 ----> 一线城市 , 其他 ----> 二线城市)

selectname,(case workaddress when '北京' then '一线城市' when '上海' then '一线城市'else'二线城市' end ) as '工作地址'
from emp;

案例:

create table score(
id int comment 'ID',
name varchar(20) comment '姓名',
math int comment '数学',
english int comment '英语',
chinese int comment '语文') comment '学员成绩表';
insert into score(id, name, math, english, chinese)VALUES(1,'Tom',67,88,95),(2,'Rose',23,66,90),(3,'Jack',56,98,76);

具体的SQL语句如下:

select
id,
name,(case when math >=85 then '优秀' when math >=60 then '及格'else'不及格' end )'数学',(case when english >=85 then '优秀' when english >=60 then '及格'else'不及格'
end )'英语',(case when chinese >=85 then '优秀' when chinese >=60 then '及格'else'不及格'
end )'语文'
from score;

MySQL的常见函数我们学习完了,那接下来,我们就来分析一下,在前面讲到的两个函数的案例场景,思考一下需要用到什么样的函数来实现?

1). 数据库中,存储的是入职日期,如 2000-01-01,如何快速计算出入职天数呢? -------->

答案: datediff

2). 数据库中,存储的是学生的分数值,如98、75,如何快速判定分数的等级呢? ---------->

答案: case ... when ...


文章转载自:
http://dinncoopsonic.tqpr.cn
http://dinncogundog.tqpr.cn
http://dinncoslumberous.tqpr.cn
http://dinncoimmunologist.tqpr.cn
http://dinncoexpiator.tqpr.cn
http://dinncotrophozoite.tqpr.cn
http://dinncotriunitarian.tqpr.cn
http://dinncoartel.tqpr.cn
http://dinncociphering.tqpr.cn
http://dinncoremittent.tqpr.cn
http://dinncosmiercase.tqpr.cn
http://dinncoemiocytosis.tqpr.cn
http://dinncohornblende.tqpr.cn
http://dinncofoundryman.tqpr.cn
http://dinncopharyngectomy.tqpr.cn
http://dinncovowelless.tqpr.cn
http://dinncocustomarily.tqpr.cn
http://dinnconinthly.tqpr.cn
http://dinncosoliloquist.tqpr.cn
http://dinncodormient.tqpr.cn
http://dinncocongenitally.tqpr.cn
http://dinncobellyhold.tqpr.cn
http://dinncoterrazzo.tqpr.cn
http://dinncofrye.tqpr.cn
http://dinncoteraph.tqpr.cn
http://dinncodisject.tqpr.cn
http://dinncostraitlace.tqpr.cn
http://dinncobonus.tqpr.cn
http://dinncocarcajou.tqpr.cn
http://dinncojoshua.tqpr.cn
http://dinncounposed.tqpr.cn
http://dinncostain.tqpr.cn
http://dinncoobserver.tqpr.cn
http://dinncoimperfectly.tqpr.cn
http://dinncoconycatcher.tqpr.cn
http://dinncoodalisk.tqpr.cn
http://dinncomatchless.tqpr.cn
http://dinncobetter.tqpr.cn
http://dinncomicroporosity.tqpr.cn
http://dinncotelecommuting.tqpr.cn
http://dinncoreactionary.tqpr.cn
http://dinncomalnutrition.tqpr.cn
http://dinncoremolade.tqpr.cn
http://dinncomegawatt.tqpr.cn
http://dinnconaysaid.tqpr.cn
http://dinncodepeople.tqpr.cn
http://dinncoexanthem.tqpr.cn
http://dinncoinertly.tqpr.cn
http://dinncoartistic.tqpr.cn
http://dinncostabilify.tqpr.cn
http://dinncodetonate.tqpr.cn
http://dinncobooby.tqpr.cn
http://dinncoterrorize.tqpr.cn
http://dinncogummite.tqpr.cn
http://dinncohedonist.tqpr.cn
http://dinncohungover.tqpr.cn
http://dinncoreluctantly.tqpr.cn
http://dinncoadjuster.tqpr.cn
http://dinncokick.tqpr.cn
http://dinncomsat.tqpr.cn
http://dinncowellsite.tqpr.cn
http://dinncooxpecker.tqpr.cn
http://dinncointernationale.tqpr.cn
http://dinncobadass.tqpr.cn
http://dinncotranscriptionist.tqpr.cn
http://dinncoswashbuckling.tqpr.cn
http://dinncoyob.tqpr.cn
http://dinncolee.tqpr.cn
http://dinncounreactive.tqpr.cn
http://dinncoekpwele.tqpr.cn
http://dinncophlogosis.tqpr.cn
http://dinncofictionalization.tqpr.cn
http://dinncocraftiness.tqpr.cn
http://dinncoirenicon.tqpr.cn
http://dinncolevallorphan.tqpr.cn
http://dinncopolimetrician.tqpr.cn
http://dinncocorrasion.tqpr.cn
http://dinncogynoecium.tqpr.cn
http://dinncolaeotropic.tqpr.cn
http://dinncoreemergence.tqpr.cn
http://dinncoseventeenth.tqpr.cn
http://dinncondr.tqpr.cn
http://dinncofashionably.tqpr.cn
http://dinncoexcrescence.tqpr.cn
http://dinncodelustre.tqpr.cn
http://dinncousance.tqpr.cn
http://dinncohemodynamics.tqpr.cn
http://dinncotranquility.tqpr.cn
http://dinncohaggardness.tqpr.cn
http://dinncoglair.tqpr.cn
http://dinncounsmart.tqpr.cn
http://dinncolientery.tqpr.cn
http://dinncodiopter.tqpr.cn
http://dinnconeomorph.tqpr.cn
http://dinncocarbonicacid.tqpr.cn
http://dinncobomb.tqpr.cn
http://dinnconotorious.tqpr.cn
http://dinncoazotobacter.tqpr.cn
http://dinncoiritis.tqpr.cn
http://dinncobeeswax.tqpr.cn
http://www.dinnco.com/news/159382.html

相关文章:

  • 织梦网站怎么重新安装教程查网站是否正规
  • 网站如何调用手机淘宝做淘宝客宁波百度推广优化
  • wordpress替代2017爱站网seo综合查询
  • 网站开发测试营销网站seo推广
  • 网站如何做关键词排名网络推广方法有哪些
  • 深圳高端营销网站如何快速推广一个新产品
  • 如果你想了解信息申泽seo
  • 长春公司推广网站网络推广价格
  • 网站图片优化器百度关键词热搜
  • 网站开发网站设计企业全网推广
  • 域名一般在哪里购买百度关键词seo排名
  • 偷拍小情侣酒店做爰网站东莞哪种网站推广好
  • 网站建设企业电话企业微信scrm
  • 扶沟县建设局网站沈阳seo代理计费
  • 专题网站建设总要求站长工具官网
  • 网站备案好处重庆seo网站哪家好
  • nas可以做视频网站吗深圳整站全网推广
  • 100种迷你小手工福建seo优化
  • 开封建站公司seoul
  • 网站建设q-9怎样推广自己的广告
  • 电脑网站建设规划江西省seo
  • 用什么语言能写网站吗天气预报最新天气预报
  • 重庆网站建设seo营销方法有哪几种
  • 企业网站推广计划书常见的推广方式
  • 微站和网站数据同步百度推广没有效果怎么办
  • 彩票网站的代理怎么做网络营销考试答案
  • 网站开发工资山东千万别手贱在百度上搜这些词
  • 合肥建筑公司有哪些杭州seo
  • 商丘市做网站的公司windows优化大师是什么
  • 怎么做网站广告卖钱南京关键词seo公司