php mysql昨日数据_统计今日、昨日的帖子数量,php mysql 语句 该如何书写?

统计今日、昨日的帖子数量,php mysql 语句 该如何书写?急!!!

回复讨论(解决方案)

建议把表结构贴出来以供分析

你数据表的结构最好发一下,因为都不知道你的数据表帖子的时间字段是什么格式的

现举最简单的表结构如下: 如提所问,php mysql 语句该如何书写?

select count(id) from table where datetime=curdate()-1 昨天

select count(id) from table where datetime=curdate() 今天

select date_format(tb_send_date, '%Y-%m-%d') as date, count(*) as cnt from tbl_name group by to_days(tb_send_date) order by desc limit 2

$today_rows="select count(*) from table where tb_send_date>='".date('Y-m-d 00:00:00')."' and tb_send_date<='".date('Y-m-d 23:59:59')."'";//今天$tomorrow=date("Y-m-d",strtotime("-1 day")); $tomorrow_rows="select count(*) from table where tb_send_date>='".$tomorrow." 00:00:00' and tb_send_date<='".$tomorrow." 23:59:59'";;//昨天

曾有人教我,mysql中where 子句尽量少用函数,因为会导致索引无效

$today_rows="select count(*) from table where tb_send_date>='".date('Y-m-d 00:00:00')."' and tb_send_date<='".date('Y-m-d 23:59:59')."'";//今天$tomorrow=date("Y-m-d",strtotime("-1 day")); $tomorrow_rows="select count(*) from table where tb_send_date>='".$tomorrow." 00:00:00' and tb_send_date<='".$tomorrow." 23:59:59'";;//昨天

曾有人教我,mysql中where 子句尽量少用函数,因为会导致索引无效

额,你说的where字句的函数 是sql的吧,貌似你搞错了

今天

select count(*) from table where date_format(tb_send_date,"%Y-%m-%d")=curdate()

昨天

select count(*) from table where date_format(tb_send_date,"%Y-%m-%d")=DATE_SUB(curdate(),INTERVAL 1 DAY)

$today_rows="select count(*) from table where tb_send_date>='".date('Y-m-d 00:00:00')."' and tb_send_date<='".date('Y-m-d 23:59:59')."'";//今天$tomorrow=date("Y-m-d",strtotime("-1 day")); $tomorrow_rows="select count(*) from table where tb_send_date>='".$tomorrow." 00:00:00' and tb_send_date<='".$tomorrow." 23:59:59'";;//昨天

曾有人教我,mysql中where 子句尽量少用函数,因为会导致索引无效

额,你说的where字句的函数 是sql的吧,貌似你搞错了

你想简单化的话,最好把你的数据库改为时间戳,好比较也好处理

$today_rows="select count(*) from table where tb_send_date>='".date('Y-m-d 00:00:00')."' and tb_send_date<='".date('Y-m-d 23:59:59')."'";//今天$tomorrow=date("Y-m-d",strtotime("-1 day")); $tomorrow_rows="select count(*) from table where tb_send_date>='".$tomorrow." 00:00:00' and tb_send_date<='".$tomorrow." 23:59:59'";;//昨天

曾有人教我,mysql中where 子句尽量少用函数,因为会导致索引无效

额,你说的where字句的函数 是sql的吧,貌似你搞错了

你想简单化的话,最好把你的数据库改为时间戳,好比较也好处理

$today_rows="select count(*) from table where tb_send_date>='".date('Y-m-d 00:00:00')."' and tb_send_date<='".date('Y-m-d 23:59:59')."'";//今天$tomorrow=date("Y-m-d",strtotime("-1 day")); $tomorrow_rows="select count(*) from table where tb_send_date>='".$tomorrow." 00:00:00' and tb_send_date<='".$tomorrow." 23:59:59'";;//昨天

曾有人教我,mysql中where 子句尽量少用函数,因为会导致索引无效

额,你说的where字句的函数 是sql的吧,貌似你搞错了

sorry,是sql

f68f2add0b68e4f9810432fce46917b7.png

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值