返回首页
当前位置: 主页 > 网络编程 > Php实例教程 >

常用mysql语句收集

时间:2012-02-28 11:47来源:知行网www.zhixing123.cn 编辑:麦田守望者

1、搜索当月数据

SELECT count( * ) AS total FROM `member` WHERE MONTH( registertime ) = MONTH( CURDATE( ) ) AND EXTRACT( YEAR FROM registertime ) = EXTRACT( YEAR FROM now( ) )

2、搜索当天数据

SELECT count( * ) AS total FROM `member` WHERE DATE( registertime ) = DATE( CURDATE( ) )
3、搜索当年数据

SELECT count( * ) as total FROM `member` WHERE EXTRACT( YEAR FROM registertime ) = EXTRACT( YEAR FROM now( ) )


4、搜索一段时间内的数据

SELECT *
FROM `paiyue` WHERE UNIX_TIMESTAMP( ’2010-02-23′ ) < UNIX_TIMESTAMP( paiyue_time ) AND UNIX_TIMESTAMP( paiyue_time ) < UNIX_TIMESTAMP( ’2010-03-23′ )

4、搜索N天前的数据

SELECT * FROM `member` WHERE date( registertime ) = date( now( ) – INTERVAL N DAY )

5、更改mysql编码与时区
mysql_query(“SET NAMES ‘utf8′”);
mysql_query(“SET CHARACTER_SET_CLIENT=utf8″);
mysql_query(“SET CHARACTER_SET_RESULTS=utf8″);
mysql_query(“SET GLOBAL time_zone = ‘+8:00′”);

------分隔线----------------------------
标签(Tag):MYSQL 数据库 mysql数据库
------分隔线----------------------------
推荐内容
猜你感兴趣