mysql中几个有用的函数

1. FROM_UNIXTIME

作用:将MYSQL中以INT(11)存储的时间以"YYYY-MM-DD"格式来显示。

例:

select mtime, from_unixtime(mtime) from topics limit 10;

2. CONCAT(str1,str2,…)

作用:将str1, str2...连接为字串。如有任何一个参数为NULL ,则返回值为 NULL。

例:

update video set playlink = concat(playlink, '&fr=abcd');

将表中所有的playlink上加一个fr参数

3. CONVERT(value,
type);

作用:将一个类型的值转换为另一个类型

可以转换的类型是有限制的。这个类型可以是以下值其中的一个:

- 二进制,同带binary前缀的效果 : BINARY

- 字符型,可带参数 : CHAR()

- 日期 : DATE

- 时间: TIME

- 日期时间型 : DATETIME

- 浮点数 : DECIMAL

- 整数 : SIGNED

- 无符号整数 : UNSIGNED

例:

假设有money字段,为了不丢失其小数的精度,我们使用varchar记录其值。但这时产生一个问题,如果要将这种字段和数字比较大小怎么办呢?

select * from bill where convert(money, DECIMAL) > 100;
时间: 2024-08-02 08:21:40

mysql中几个有用的函数的相关文章

dbus 创建Client过程中几个有用的函数

/**  * g_type_init:  *  * This function used to initialise the type system.  Since GLib 2.36,  * the type system is initialised automatically and this function does  * nothing.  *  * Deprecated: 2.36: the type system is now initialised automatically

MySQL中的内置系统函数

MySQL中的内置系统函数 用在SELECCT语句, 能及子句 where order by having 中 UPDATE DELETE, 函数中可以将字段名作为变量来用,变量的值就是这个列对应的每一行记录 一.字符串函数 php中用的函数,MySQl中大部也提供 1. CONCAT(S1,S2....SN): 把传入的参数连接成一个字符串 2. INSERT(str, x, y, insert): 将字符串X位置开始,y个字符串长度替换为字符串insert 3. LOWER(str) UPP

mysql中返回当前时间的函数或者常量

引用:http://blog.sina.com.cn/s/blog_6d39dc6f0100m7eo.html 1.1 获得当前日期+时间(date + time)函数:now() 除了 now() 函数能获得当前的日期时间外,MySQL 中还有下面的函数: current_timestamp()   current_timestamp localtime()   localtime localtimestamp()   localtimestamp     这些日期时间函数,都等同于 now(

MySQL中好用的GROUP_CONCAT函数

今天看到同事的代码,又学到了一个有用的函数,刚看的时候不太懂,就搜了下用法,看下面这篇文章讲的挺详细就直接转载了,我也写不那么好,呵呵,感谢作者的无私奉献. http://blog.sina.com.cn/s/blog_4e808acf01009qna.html  作者:miky GROUP_CONCAT()是MySQL数据库提供的一个函数,通常跟GROUP BY一起用,具体可参考MySQL官方文挡:http://dev.mysql.com/doc/refman/5.0/en/group-by-

MYSQL中关于日期处理的函数

< DOCTYPE HTML PUBLIC -WCDTD HTML TransitionalEN> MySQL数据库中SQL语句中 关于日期.时间\时间戳的函数 一 MySQL 获得当前日期时间 函数 1.1 获得当前日期+时间(date + time)函数:now() mysql> select now(); +―――――――+| now() |+―――――――+| 2008-08-08 22:20:46 |+―――――――+除了 now() 函数能获得当前的日期时间外,MySQL 中

mysql中的count()函数使用

有时候总认为count(*)会比count(1)或者count(column name)慢,事实上是分情况处理. 比如: ---初始化语句 建立一张表并插入数据: create table test2 (id BIGINT PRIMARY key, name varchar(24))ENGINE=INNODB; insert into test2(id,name)values(1,null); insert into test2(id,name)values(2,'name1'); insert

MySQL中默认值中用时间函数的问题

今天在上课的时候在测试MSSQL建表的时候 注册时间默认值用getdate()可以获取插入值时候的时间create table temp( id int PRIMARY key, in_time datetime NOT NULL default getdate() ) 但是在MYSQL建表练习的时候不能用now()进行对应的做法: create table temp(    id int PRIMARY key,    in_time datetime NOT NULL default now

MySQL中的两个时间函数,用来做两个时间之间的对比

TIMESTAMPDIFF,(如果当期时间和之前时间的分钟数相比较.大于1天,即等于1:小于1天,则等于0) select TIMESTAMPDIFF(DAY,'2016-11-16 10:13:42',NOW()); DATEDIFF,(只按2016-11-16计算,不会加小时分钟数,按天计算) select DATEDIFF(NOW(),'2016-11-16 17:10:52'); 在SQL Server中,DATEDIFF要比MySQL强大,但是我不没用过. 来自为知笔记(Wiz)

mysql 中 unix_timestamp,from_unixtime 时间戳函数

1.unix_timestamp 将时间转化为时间戳.(date 类型数据转换成 timestamp 形式整数) 没传时间参数则取当前时间的时间戳 mysql> select unix_timestamp();+------------------+| unix_timestamp() |+------------------+|       1361586358 |+------------------+1 row in set (0.01 sec) mysql> select unix_t