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

做外贸哪些网站可以找客户网站优化入门免费教程

做外贸哪些网站可以找客户,网站优化入门免费教程,用PS做网站搜索框,苏州专业做网站的公司内置函数 日期函数示例案例-1案例-2 字符串函数示例 数学函数其他函数 日期函数 示例 获得当前年月日 mysql> select current_date(); ---------------- | current_date() | ---------------- | 2023-09-03 | ---------------- 1 row in set (0.00 sec)获得当前时分秒…

内置函数

  • 日期函数
    • 示例
    • 案例-1
    • 案例-2
  • 字符串函数
    • 示例
  • 数学函数
  • 其他函数

日期函数

在这里插入图片描述

示例

  • 获得当前年月日
mysql> select current_date();
+----------------+
| current_date() |
+----------------+
| 2023-09-03     |
+----------------+
1 row in set (0.00 sec)
  • 获得当前时分秒
mysql> select current_time;
+--------------+
| current_time |
+--------------+
| 09:20:15     |
+--------------+
1 row in set (0.00 sec)
  • 获得当前时间戳

mysql中该函数会自动将时间戳转化为年月日时分秒的格式

mysql> select current_timestamp();
+---------------------+
| current_timestamp() |
+---------------------+
| 2023-09-03 09:20:49 |
+---------------------+
1 row in set (0.00 sec)
  • date(datetime),返回 datetime 参数中的日期部分(年月日部分)
mysql> select date(current_date());
+----------------------+
| date(current_date()) |
+----------------------+
| 2023-09-03           |
+----------------------+
1 row in set (0.00 sec)//虽然currnt_time()获得的只有时分秒时间,但该函数内部获得时间的时候是可以获得日期(年月日)的
mysql> select date(current_time());
+----------------------+
| date(current_time()) |
+----------------------+
| 2023-09-03           |
+----------------------+
1 row in set (0.00 sec)mysql> select date(current_timestamp());
+---------------------------+
| date(current_timestamp()) |
+---------------------------+
| 2023-09-03                |
+---------------------------+
1 row in set (0.00 sec)
  • 在日期的基础上加上日期
//在 2023-9-3 的基础上加上 50 天
mysql> select date_add('2023-9-3',interval 50 day);
+--------------------------------------+
| date_add('2023-9-3',interval 50 day) |
+--------------------------------------+
| 2023-10-23                           |
+--------------------------------------+
1 row in set (0.00 sec)
  • 在日期的基础上减去日期
//在 2023-10-23 的基础上减去 50 天
mysql> select date_sub('2023-10-23',interval 50 day);
+----------------------------------------+
| date_sub('2023-10-23',interval 50 day) |
+----------------------------------------+
| 2023-09-03                             |
+----------------------------------------+
1 row in set (0.00 sec)
  • 计算两个日期相差多少天
mysql> select datediff('2023-9-3','2023-10-23');
+-----------------------------------+
| datediff('2023-9-3','2023-10-23') |
+-----------------------------------+
|                               -50 |
+-----------------------------------+
1 row in set (0.00 sec)

案例-1

  • 创建一张表,记录生日
mysql> create table tmp (id int primary key auto_increment,birthday date not null);
Query OK, 0 rows affected (0.01 sec)mysql> desc tmp;
+----------+---------+------+-----+---------+----------------+
| Field    | Type    | Null | Key | Default | Extra          |
+----------+---------+------+-----+---------+----------------+
| id       | int(11) | NO   | PRI | NULL    | auto_increment |
| birthday | date    | NO   |     | NULL    |                |
+----------+---------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
  • 添加当前日期
mysql> insert into tmp(birthday) values(current_date());
Query OK, 1 row affected (0.00 sec)mysql> select* from tmp;
+----+------------+
| id | birthday   |
+----+------------+
|  1 | 2023-09-03 |
+----+------------+
1 row in set (0.00 sec)

案例-2

  • 创建一个留言表
mysql> create table msg(id int primary key auto_increment,content varchar(30) not null,sendtime datetime);
Query OK, 0 rows affected (0.01 sec)mysql> desc msg;
+----------+-------------+------+-----+---------+----------------+
| Field    | Type        | Null | Key | Default | Extra          |
+----------+-------------+------+-----+---------+----------------+
| id       | int(11)     | NO   | PRI | NULL    | auto_increment |
| content  | varchar(30) | NO   |     | NULL    |                |
| sendtime | datetime    | YES  |     | NULL    |                |
+----------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
  • 插入数据
mysql> insert into msg(content,sendtime) values('hello',now());
Query OK, 1 row affected (0.00 sec)mysql> insert into msg(content,sendtime) values('hi',now());
Query OK, 1 row affected (0.00 sec)mysql> select* from msg;
+----+---------+---------------------+
| id | content | sendtime            |
+----+---------+---------------------+
|  1 | hello   | 2023-09-03 09:48:45 |
|  2 | hi      | 2023-09-03 09:48:52 |
+----+---------+---------------------+
2 rows in set (0.00 sec)
  • 显示所有留言信息,发布日期只显示到年月日,不用显示具体时间
mysql> select content ,date(sendtime) from msg;
+---------+----------------+
| content | date(sendtime) |
+---------+----------------+
| hello   | 2023-09-03     |
| hi      | 2023-09-03     |
+---------+----------------+
2 rows in set (0.00 sec)
  • 查询在 10 分钟内发布的帖子
mysql> select* from msg where date_add(sendtime,interval 10 minute) > now();
+----+---------+---------------------+
| id | content | sendtime            |
+----+---------+---------------------+
|  1 | hello   | 2023-09-03 09:48:45 |
|  2 | hi      | 2023-09-03 09:48:52 |
+----+---------+---------------------+
2 rows in set (0.00 sec)
理解:------------------------------|-----------|-------------|------------------初始时间     now()       初始时间+10min  

字符串函数

在这里插入图片描述

示例

  • 获取表中的某一列的字符集
mysql> select charset(content) from msg;
+------------------+
| charset(content) |
+------------------+
| utf8             |
| utf8             |
+------------------+
2 rows in set (0.00 sec)
  • 字符串连接
mysql> select concat('app','le');
+--------------------+
| concat('app','le') |
+--------------------+
| apple              |
+--------------------+
1 row in set (0.00 sec)
  • 某字符串中是否包含某子串,包含则返回出现的位置,未包含则返回 0
mysql> select instr('apple','ple');
+----------------------+
| instr('apple','ple') |
+----------------------+
|                    3 |
+----------------------+
1 row in set (0.00 sec)mysql> select instr('apple','b');
+--------------------+
| instr('apple','b') |
+--------------------+
|                  0 |
+--------------------+
1 row in set (0.00 sec)
  • 转换成大写
mysql> select ucase('abcA');
+---------------+
| ucase('abcA') |
+---------------+
| ABCA          |
+---------------+
1 row in set (0.00 sec)
  • 转换成小写
mysql> select lcase('abcA');
+---------------+
| lcase('abcA') |
+---------------+
| abca          |
+---------------+
1 row in set (0.00 sec)
  • 从字符串的左边或者右边起取 length 个字符
mysql> select left('abcdef',2);
+------------------+
| left('abcdef',2) |
+------------------+
| ab               |
+------------------+
1 row in set (0.00 sec)mysql> select right('abcdef',2);
+-------------------+
| right('abcdef',2) |
+-------------------+
| ef                |
+-------------------+
1 row in set (0.00 sec)
  • 获取字符串的长度
mysql> select length('abc');
+---------------+
| length('abc') |
+---------------+
|             3 |
+---------------+
1 row in set (0.00 sec)mysql> select length('你好');
+------------------+
| length('你好')   |
+------------------+
|                6 |
+------------------+
1 row in set (0.00 sec)

注意:length函数返回字符串长度,以字节为单位。如果是多字节字符则计算多个字节数;
如果是单字节字符则算作一个字节。比如:字母,数字算作一个字节,中文表示多个字节数
(与字符集编码有关)

  • 在字符串中用某子串替换掉其中的子串
//在 ‘hello world’ 中用 ‘jack’ 替换掉 ‘world’
mysql> select replace('hello world','world','jack');
+---------------------------------------+
| replace('hello world','world','jack') |
+---------------------------------------+
| hello jack                            |
+---------------------------------------+
1 row in set (0.00 sec)
  • 逐字符比较字符串的大小
//第一个字符串小于第二个字符串返回 -1
mysql> select strcmp('abc','abd');
+---------------------+
| strcmp('abc','abd') |
+---------------------+
|                  -1 |
+---------------------+
1 row in set (0.00 sec)//相等返回 0
mysql> select strcmp('abc','abc');
+---------------------+
| strcmp('abc','abc') |
+---------------------+
|                   0 |
+---------------------+
1 row in set (0.00 sec)//大于返回 1
mysql> select strcmp('abd','abc');
+---------------------+
| strcmp('abd','abc') |
+---------------------+
|                   1 |
+---------------------+
1 row in set (0.00 sec)
  • 从字符串的第 position 开始,取 length 个字符
//从第一个位置开始取三个字符
mysql> select substring('abcdefg','1',3);
+----------------------------+
| substring('abcdefg','1',3) |
+----------------------------+
| abc                        |
+----------------------------+
1 row in set (0.00 sec)
  • 去除 前空格 / 后空格 / 前后空格
mysql> select '   hello   ' as res;
+-------------+
| res         |
+-------------+
|    hello    |
+-------------+
1 row in set (0.00 sec)mysql> select ltrim('   hello   ') as res;//去除前空格
+----------+
| res      |
+----------+
| hello    |
+----------+
1 row in set (0.00 sec)mysql> select rtrim('   hello   ') as res;//去除后空格
+----------+
| res      |
+----------+
|    hello |
+----------+
1 row in set (0.00 sec)mysql> select trim('   hello   ') as res; //去除前后空格
+-------+
| res   |
+-------+
| hello |
+-------+
1 row in set (0.00 sec)

数学函数

在这里插入图片描述

  • 绝对值
mysql> select abs(-100.5);
+-------------+
| abs(-100.5) |
+-------------+
|       100.5 |
+-------------+
1 row in set (0.00 sec)
  • 向上取整
mysql> select ceiling(23.4);
+---------------+
| ceiling(23.4) |
+---------------+
|            24 |
+---------------+
1 row in set (0.00 sec)
  • 向下取整
mysql> select floor(24.7);
+-------------+
| floor(24.7) |
+-------------+
|          24 |
+-------------+
1 row in set (0.00 sec)
  • 保留小数位数
//保留2位小数位数(小数四舍五入)
mysql> select format(12.3456,2);
+-------------------+
| format(12.3456,2) |
+-------------------+
| 12.35             |
+-------------------+
1 row in set (0.00 sec)
  • 产生随机数
mysql> select rand();
+--------------------+
| rand()             |
+--------------------+
| 0.2013088168588549 |
+--------------------+
1 row in set (0.00 sec)mysql> select rand();
+--------------------+
| rand()             |
+--------------------+
| 0.2613807602425858 |
+--------------------+
1 row in set (0.00 sec)

其他函数

  • user() 查询当前用户
  • md5(str)对一个字符串进行md5摘要,摘要后得到一个32位字符串
  • database()显示当前正在使用的数据库
  • password()函数,MySQL数据库使用该函数对用户加密
  • ifnull(val1, val2) 如果val1为null,返回val2,否则返回val1的值
http://www.hkea.cn/news/253209/

相关文章:

  • 网站平台怎么建立的软文范例
  • 移动应用开发专业学什么东莞seo软件
  • 做宣传网站的公司手机百度极速版app下载安装
  • 私人可以做慈善网站吗外贸如何推广
  • 网站页面模板页面布局如何成为百度广告代理商
  • 瑞安外贸网站建设曲靖百度推广
  • 先做网站还是服务器销售营销方案100例
  • 用卫生纸做的礼物街网站免费网页空间到哪申请
  • 手游网站做cpc还是cpm广告号厦门网页搜索排名提升
  • 人个做外贸用什么网站好宁波百度seo点击软件
  • 诈骗网站怎么做的企业网站seo案例分析
  • 如何做网站接口湖南营销型网站建设
  • 进入兔展网站做PPt软文营销ppt
  • app网站新闻危机公关
  • 东莞关键词优化实力乐云seo南宁seo外包服务商
  • 做网站都是用源码么免费注册个人网站不花钱
  • 建设网站需要两种服务支持官网设计公司
  • 安庆做网站seo建站收费地震
  • 绵阳住房和城市建设局网站官网seo排名优化联系13火星软件
  • 网站开发建设费用关键词异地排名查询
  • 网站建设企业电话广州优化疫情防控举措
  • 重庆模板网站建设百度网站域名注册
  • 安徽建设厅网站地址网络广告推广方式
  • 门户网站内容管理建设方案企业关键词优化推荐
  • 北京网站建设公司飞沐小学生一分钟新闻播报
  • 企业网站建设申请域名seo赚钱
  • 2017网站开发前景百度网盘资源链接入口
  • 平面广告设计主题seo是怎么优化上去
  • 正规网站制作公司哪家好四年级写一小段新闻
  • 济南网站建设安卓版快手seo