最新消息: 新版网站上线了!!!

Mysql 查找当天记录语句

Mysql 查找当天记录语句
 
有些函数一直未发现,知道经常才知道,愧疚啊
 
本季度的第一天 ,然后你可以把字符串再转换为日期。 方法很多,包括同一个函数的别名(同义词)也很多。比如CURDATE(),CURRENT_DATE(), CURRENT_DATE, NOW 等都可以返回当天
 
 
mysql教程> select CURDATE(),ELT(QUARTER(CURDATE()),
    ->  year(CURDATE())*1000+0101,
    ->  year(CURDATE())*1000+0401,
    ->  year(CURDATE())*1000+0701,
    ->  year(CURDATE())*1000+1001) as firstDayofQ;
+------------+-------------+
| CURDATE()  | firstDayofQ |
+------------+-------------+
| 2009-05-19 | 2009401     |
+------------+-------------+
1 row in set (0.00 sec)
 
mysql>
 
 
用mysql语句获取本季度的第一天
 
本月的第一天,
date(
concat(year(curdate()),'-',month(curdate()),'-','1'))
本周的第一天
curdate()-
WEEKDAY(curdate())
 
 
用mysql语句获取本季度的第一天
 
date(
concat(year(curdate()),'-',
if(quarter(curdate())=1,1,if(quarter(curdate())=2,4,if(quarter(curdate())=3,7,10))
 
 
 
用mysql语句获取本季度的第一天:
优化:
date(
concat(year(curdate()),'-',elt(quarter(curdate()),1,4,7,10),'-',1))
 
 
本周的第一天
date_add(date('2009-5-29'),INTERVAL -weekday('2009-5-29') day)
 
mysql 获取当天发布文件内容sql语句
 
SELECT * FROM `p8_memberdata` where regdate BETWEEN (UNIX_TIMESTAMP(NOW())-86440) AND NOW()
SELECT * FROM `p8_memberdata` WHERE DATE_FORMAT(FROM_UNIXTIME(regdate),'%Y-%m-%d')= DATE_FORMAT(NOW(),'%Y-%m-%d') order by uid desc
某一天内某一帖的回复人数,排除同一个多次回复的情况
SELECT COUNT(DISTINCT author_id,subject_id,(DATE_FORMAT(`create_time` , '%Y-%m-%d'))) FROM COMMENT  
WHERE subject_id IN (SELECT id FROM group_post WHERE group_id=5135203559277568 ) 
 
导出某个表里指定的记录,命令行模式下导出:
mysqldump -h 127.0.0.1 -uroot -p123456 sns groups -x --where " id IN (SELECT groupid FROM  activity_group)" > a.sql
 
 
查找表中当日插进的记录
SELECT * FROM table_name WHERE DATEDIFF(create_time,NOW())=0
 

转载请注明:谷谷点程序 » Mysql 查找当天记录语句