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

信阳住房和城乡建设厅网站网络销售怎么才能找到客户

信阳住房和城乡建设厅网站,网络销售怎么才能找到客户,网站行业认证怎么做,杭州网站建设外包目录 1.日期函数 1.1获得年月日 1.2获得时分秒 1.3获得年月日时分秒 1.4获得时间戳 1.5日期加天数 1.6日期减天数 1.7计算两个日期相隔多少天 1.8案例 2.字符串函数 2.1获取字符集 2.2字符串拼接 2.3字符串查询 2.4大小写转换 2.5字符串提取 2.6字符串长度 2.7…

目录

1.日期函数

1.1获得年月日

1.2获得时分秒

1.3获得年月日时分秒

1.4获得时间戳

1.5日期加天数

1.6日期减天数

1.7计算两个日期相隔多少天

1.8案例

2.字符串函数

2.1获取字符集

2.2字符串拼接

2.3字符串查询

2.4大小写转换

2.5字符串提取

2.6字符串长度

2.7字符串替换

2.8字符串截取

2.9去除空格

3.数学函数

3.1绝对值

3.2转二进制

3.3转十六进制

3.4进制转换

3.5向上向下取整

3.6保留n位小数

3.7随机数

3.8取模

4.其他函数

4.1查询当前用户

4.2显示当前数据库

4.3md5摘要

4.4passwor加密

4.5ifnull


1.日期函数

1.1获得年月日

mysql> select current_date();
+----------------+
| current_date() |
+----------------+
| 2024-03-24     |
+----------------+
1 row in set (0.00 sec)

1.2获得时分秒

mysql> select current_time();
+----------------+
| current_time() |
+----------------+
| 22:10:04       |
+----------------+
1 row in set (0.00 sec)

1.3获得年月日时分秒

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2024-03-24 22:30:14 |
+---------------------+
1 row in set (0.00 sec)

1.4获得时间戳

会以日期的方式显示。

mysql> select current_timestamp();
+---------------------+
| current_timestamp() |
+---------------------+
| 2024-03-24 22:10:55 |
+---------------------+
1 row in set (0.00 sec)

1.5日期加天数

mysql> select date_add('2022-01-01', interval 12 day) as res;
+------------+
| res        |
+------------+
| 2022-01-13 |
+------------+
1 row in set (0.00 sec)mysql> select date_add('2022-01-01', interval 3 month) as res;
+------------+
| res        |
+------------+
| 2022-04-01 |
+------------+
1 row in set (0.00 sec)

1.6日期减天数

mysql> select date_sub('2022-01-01', interval 12 day) as res;
+------------+
| res        |
+------------+
| 2021-12-20 |
+------------+
1 row in set (0.00 sec)mysql> select date_sub('2022-01-01', interval 3 month) as res;
+------------+
| res        |
+------------+
| 2021-10-01 |
+------------+
1 row in set (0.00 sec)

1.7计算两个日期相隔多少天

mysql> select datediff('2024-03-24', '2022-01-01') as res;
+------+
| res  |
+------+
|  813 |
+------+
1 row in set (0.00 sec)


1.8案例

  • 创建一张生日表
mysql> create table bir(-> id int primary key auto_increment,-> birthday date-> );
Query OK, 0 rows affected (0.02 sec)mysql> insert into bir(birthday) values('1998-05-28');
Query OK, 1 row affected (0.00 sec)mysql> insert into bir(birthday) values(current_date);
Query OK, 1 row affected (0.00 sec)mysql> insert into bir(birthday) values(current_timestamp());
Query OK, 1 row affected, 1 warning (0.00 sec)mysql> insert into bir(birthday) values(date(current_timestamp()));
Query OK, 1 row affected (0.00 sec)mysql> select * from bir;
+----+------------+
| id | birthday   |
+----+------------+
|  1 | 2024-03-24 |
|  2 | 1998-05-28 |
|  3 | 2024-03-24 |
|  4 | 2024-03-24 |
+----+------------+
4 rows in set (0.00 sec)

第三次插入的为时间戳,mysql会自动转化为日期。

  • 创建一个留言表
mysql> create table mes(-> id int primary key auto_increment,-> message varchar(100) not null,-> sendtime datetime-> );
Query OK, 0 rows affected (0.02 sec)mysql> insert into mes (message, sendtime) values ('窗前明月光', now());
Query OK, 1 row affected (0.00 sec)mysql> insert into mes (message, sendtime) values ('疑是地上霜', now());
Query OK, 1 row affected (0.00 sec)mysql> select * from mes;
+----+-----------------+---------------------+
| id | message         | sendtime            |
+----+-----------------+---------------------+
|  1 | 窗前明月光      | 2024-03-24 22:29:33 |
|  2 | 疑是地上霜      | 2024-03-24 22:29:43 |
+----+-----------------+---------------------+
2 rows in set (0.00 sec)
  • 查询3分钟之内发的评论
mysql> select * from mes
+----+-----------------+---------------------+
| id | message         | sendtime            |
+----+-----------------+---------------------+
|  1 | 窗前明月光      | 2024-03-24 22:29:33 |
|  2 | 疑是地上霜      | 2024-03-24 22:29:43 |
|  3 | 举头望明月      | 2024-03-24 22:31:42 |
|  4 | 低头思故乡      | 2024-03-24 22:31:49 |
+----+-----------------+---------------------+
4 rows in set (0.00 sec)mysql> select * from mes where sendtime > date_sub(now(), interval 3 minute);
+----+-----------------+---------------------+
| id | message         | sendtime            |
+----+-----------------+---------------------+
|  3 | 举头望明月      | 2024-03-24 22:31:42 |
|  4 | 低头思故乡      | 2024-03-24 22:31:49 |
+----+-----------------+---------------------+
2 rows in set (0.00 sec)

2.字符串函数

2.1获取字符集

mysql> select charset('123');
+----------------+
| charset('123') |
+----------------+
| utf8           |
+----------------+
1 row in set (0.00 sec)mysql> select charset(123);
+--------------+
| charset(123) |
+--------------+
| binary       |
+--------------+
1 row in set (0.00 sec)mysql> select charset(sendtime) from mes;
+-------------------+
| charset(sendtime) |
+-------------------+
| binary            |
| binary            |
| binary            |
| binary            |
+-------------------+
4 rows in set (0.00 sec)

2.2字符串拼接

类似于c语言中的strcat

mysql> select concat('123', 'hello', 'world') as res;
+---------------+
| res           |
+---------------+
| 123helloworld |
+---------------+
1 row in set (0.00 sec)
mysql> select concat('id: ', id, ' 发送了一条消息: ', message, ' 时间:', sendtime) as res from mes;
+-------------------------------------------------------------------------+
| res                                                                     |
+-------------------------------------------------------------------------+
| id: 1 发送了一条消息: 窗前明月光 时间:2024-03-24 22:29:33               |
| id: 2 发送了一条消息: 疑是地上霜 时间:2024-03-24 22:29:43               |
| id: 3 发送了一条消息: 举头望明月 时间:2024-03-24 22:31:42               |
| id: 4 发送了一条消息: 低头思故乡 时间:2024-03-24 22:31:49               |
+-------------------------------------------------------------------------+
4 rows in set (0.00 sec)

2.3字符串查询

instr(string, substring) 返回substring在string中的下标(从1开始),不存在返回0。

mysql> select instr('helfjsadio123fjkdsfa', '123');
+--------------------------------------+
| instr('helfjsadio123fjkdsfa', '123') |
+--------------------------------------+
|                                   11 |
+--------------------------------------+
1 row in set (0.00 sec)

2.4大小写转换

ucase转大写,lcase转小写。

mysql> select ucase('fAjfkjBSD213jD1s');
+---------------------------+
| ucase('fAjfkjBSD213jD1s') |
+---------------------------+
| FAJFKJBSD213JD1S          |
+---------------------------+
1 row in set (0.00 sec)
mysql> select lcase('fAjfkjBSD213jD1s');
+---------------------------+
| lcase('fAjfkjBSD213jD1s') |
+---------------------------+
| fajfkjbsd213jd1s          |
+---------------------------+
1 row in set (0.00 sec)

2.5字符串提取

left(string, length),string中从左往右提取length个字符。

mysql> select left('hello world', 8);
+------------------------+
| left('hello world', 8) |
+------------------------+
| hello wo               |
+------------------------+
1 row in set (0.00 sec)

right(string, length)),stringg中从右向左提取length个字符。

mysql> select right('hello world', 7);
+-------------------------+
| right('hello world', 7) |
+-------------------------+
| o world                 |
+-------------------------+
1 row in set (0.00 sec)

2.6字符串长度

mysql> select length('fds28f3j28x');
+-----------------------+
| length('fds28f3j28x') |
+-----------------------+
|                    11 |
+-----------------------+
1 row in set (0.00 sec)

案例:求学生表中学生姓名占用的字节数

mysql> select name, length(name) 长度 from exam_result;
+-----------+--------+
| name      | 长度   |
+-----------+--------+
| 唐三藏    |      9 |
| 猪悟能    |      9 |
| 曹孟德    |      9 |
| 刘玄德    |      9 |
| 孙权      |      6 |
| 宋公明    |      9 |
| 张翼德    |      9 |
| 关云长    |      9 |
+-----------+--------+
8 rows in set (0.00 sec)

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

2.7字符串替换

replace(str, s1, s2),在str中,用s2替换s1。

mysql> select replace('hello world', 'world', 'mysql');
+------------------------------------------+
| replace('hello world', 'world', 'mysql') |
+------------------------------------------+
| hello mysql                              |
+------------------------------------------+
1 row in set (0.00 sec)

案例:将表中所有姓孙的同学改成姓周。

mysql> select name from exam_result;
+-----------+
| name      |
+-----------+
| 唐三藏    |
| 猪悟能    |
| 曹孟德    |
| 刘玄德    |
| 孙权      |
| 宋公明    |
| 张翼德    |
| 关云长    |
+-----------+
8 rows in set (0.00 sec)mysql> select replace(name, '孙', '周') from exam_result;
+-----------------------------+
| replace(name, '孙', '周')   |
+-----------------------------+
| 唐三藏                      |
| 猪悟能                      |
| 曹孟德                      |
| 刘玄德                      |
| 周权                        |
| 宋公明                      |
| 张翼德                      |
| 关云长                      |
+-----------------------------+
8 rows in set (0.00 sec)

注意:select和replace配合使用并不会修改数据库中的数据。

2.8字符串截取

substring(str, pos, length),str中的pos位置开始截取length个字符。length不写表示截取完。

mysql> select substring('fja382nqf8q8n2nc', 4);
+----------------------------------+
| substring('fja382nqf8q8n2nc', 4) |
+----------------------------------+
| 382nqf8q8n2nc                    |
+----------------------------------+
1 row in set (0.00 sec)mysql> select substring('fja382nqf8q8n2nc', 4, 5);
+-------------------------------------+
| substring('fja382nqf8q8n2nc', 4, 5) |
+-------------------------------------+
| 382nq                               |
+-------------------------------------+
1 row in set (0.00 sec)

案例:截取name中第二个到第三个字段。

mysql> select name, substring(name, 2, 2) from exam_result;
+-----------+-----------------------+
| name      | substring(name, 2, 2) |
+-----------+-----------------------+
| 唐三藏    | 三藏                  |
| 猪悟能    | 悟能                  |
| 曹孟德    | 孟德                  |
| 刘玄德    | 玄德                  |
| 孙权      | 权                    |
| 宋公明    | 公明                  |
| 张翼德    | 翼德                  |
| 关云长    | 云长                  |
+-----------+-----------------------+
8 rows in set (0.00 sec)

2.9去除空格

ltrim去除左边空格,rtrim去除右边的空格。

mysql> select ltrim('  nihao  ') as res;
+---------+
| res     |
+---------+
| nihao   |
+---------+
1 row in set (0.00 sec)mysql> select rtrim('  nihao  ') as res;
+---------+
| res     |
+---------+
|   nihao |
+---------+
1 row in set (0.00 sec)

3.数学函数

3.1绝对值

mysql> select abs(-21);
+----------+
| abs(-21) |
+----------+
|       21 |
+----------+
1 row in set (0.00 sec)

3.2转二进制

mysql> select bin(7);
+--------+
| bin(7) |
+--------+
| 111    |
+--------+
1 row in set (0.00 sec)

3.3转十六进制

mysql> select hex(41);
+---------+
| hex(41) |
+---------+
| 29      |
+---------+
1 row in set (0.00 sec)

3.4进制转换

任意两种进制之间的转换

mysql> select conv(21, 10, 4);
+-----------------+
| conv(21, 10, 4) |
+-----------------+
| 111             |
+-----------------+
1 row in set (0.00 sec)

十进制转四进制

3.5向上向下取整

ceiling向上取整,floor向下取整

mysql> select ceiling(2.11);
+---------------+
| ceiling(2.11) |
+---------------+
|             3 |
+---------------+
1 row in set (0.00 sec)mysql> select floor(2.11);
+-------------+
| floor(2.11) |
+-------------+
|           2 |
+-------------+
1 row in set (0.00 sec)

3.6保留n位小数

mysql> select format(1.234578, 5);
+---------------------+
| format(1.234578, 5) |
+---------------------+
| 1.23458             |
+---------------------+
1 row in set (0.00 sec)

3.7随机数

mysql> select rand();
+---------------------+
| rand()              |
+---------------------+
| 0.21503182520627215 |
+---------------------+
1 row in set (0.00 sec)mysql> select rand();
+--------------------+
| rand()             |
+--------------------+
| 0.8824897100054563 |
+--------------------+
1 row in set (0.00 sec)

3.8取模

mysql> select mod(10, 3);
+------------+
| mod(10, 3) |
+------------+
|          1 |
+------------+
1 row in set (0.00 sec)

4.其他函数

4.1查询当前用户

mysql> select user();
+--------+
| user() |
+--------+
| root@  |
+--------+
1 row in set (0.00 sec)

4.2显示当前数据库

mysql> select database();
+------------+
| database() |
+------------+
| user5      |
+------------+
1 row in set (0.00 sec)

4.3md5摘要

如果当前数据库存储的是密码,并且是以明文的形式保存的,如果被黑客攻击了,拿到了数据库中所有人的密码,那就麻烦了,针对这种情况,保存密码可以使用md5形成一个32位的数据摘要。

mysql> create table user(-> id int primary key auto_increment,-> name varchar(20) not null,-> password char(32) not null-> );
Query OK, 0 rows affected (0.02 sec)mysql> insert into user(name, password) values('张三', 1234);
Query OK, 1 row affected (0.00 sec)mysql> insert into user(name, password) values('李四', md5('1234'));
Query OK, 1 row affected (0.00 sec)mysql> select * from user;
+----+--------+----------------------------------+
| id | name   | password                         |
+----+--------+----------------------------------+
|  1 | 张三   | 1234                             |
|  2 | 李四   | 81dc9bdb52d04dc20036dbd8313ed055 |
+----+--------+----------------------------------+
2 rows in set (0.00 sec)

当用户登录的时候,只需要使用用户名和md5后的摘要在表中查找,如果找到了说明密码正确

mysql> select * from user where name='李四' and password=md5('1234');
+----+--------+----------------------------------+
| id | name   | password                         |
+----+--------+----------------------------------+
|  2 | 李四   | 81dc9bdb52d04dc20036dbd8313ed055 |
+----+--------+----------------------------------+
1 row in set (0.00 sec)

4.4passwor加密

在上述例子当中,我们也可以使用passw进行加密

mysql> select password('1234');
+-------------------------------------------+
| password('1234')                          |
+-------------------------------------------+
| *A4B6157319038724E3560894F7F932C8886EBFCF |
+-------------------------------------------+
1 row in set, 1 warning (0.00 sec)mysql> select md5('1234');
+----------------------------------+
| md5('1234')                      |
+----------------------------------+
| 81dc9bdb52d04dc20036dbd8313ed055 |
+----------------------------------+
1 row in set (0.00 sec)

可以看到两种方式得到的摘要是不同的。

4.5ifnull

ifnull(val1, val2) 如果val1为null,返回val2,否则返回val1的值

mysql> select ifnull(123, 456);
+------------------+
| ifnull(123, 456) |
+------------------+
|              123 |
+------------------+
1 row in set (0.00 sec)mysql> select ifnull(null, 456);
+-------------------+
| ifnull(null, 456) |
+-------------------+
|               456 |
+-------------------+
1 row in set (0.00 sec)

http://www.dtcms.com/wzjs/325086.html

相关文章:

  • iis 网站 红百度seo快排软件
  • vi设计网站排行榜西安区seo搜索排名优化
  • 网站开发命名规则百度一下就知道官方
  • asp.net网站建设论文网络推广公司是干什么
  • 做网站可以自由职业吗清远新闻最新
  • 海南海口做网站关键词是什么
  • 网站建设中正在为您转关键词排名软件
  • 找手工活带回家做的找工作哪个网站最靠谱网络营销公司网络推广
  • 推荐几个做网站比较好的公司小红书推广方式
  • 坪山附近网站建设大数据
  • 网站访客qq提取拼多多怎么查商品排名
  • 一级a做爰片免费无码网站友情链接买卖代理
  • 网站建设与用户体验关键词优化推广公司
  • 做网站 花时间购买友情链接
  • 携程旅行网站内容的建设网络营销公司哪家可靠
  • 个体工商营业执照注册查询金华seo全网营销
  • 唐山网站建设哪家优惠乐事薯片软文推广
  • 购物网站需要哪些模块如何制作链接推广
  • 如何使用云服务建设网站杭州网站推广找哪家
  • 用网站ip做代理chrome官网下载
  • 网站备案没座机移动网站优化排名
  • 网站添加favicon九江seo优化
  • 建网站能上传多少数据seo关键词排名点击工具
  • 房地产销售头像seo百度关键词优化软件
  • 财富半岛建设购物网站百度排行榜
  • 电子商务网站首页天津百度推广公司
  • 网站建设情况百度官网优化
  • 建设网站要求和注意事项app开发工具哪个好
  • 做鞋子出口需要作网站吗外贸获客软件
  • 宝安区建设局网站常用的搜索引擎