mysql sql语句检索开始日期和结束日期,并且检索日期为空的数据
web SQL 2021-06-08 1945 0
关于本站

“最难不过坚持”

本人承接扒站仿站,php网站维护,病毒查杀,网站编辑,网站改版,html制作

有需要网站维护,改版,病毒查杀,网站编辑,网站备案,html制作等相关的工作可以联系我。
本人有多年相关工作经验,也可提供免费咨询,交个朋友。
有需要探讨问题的朋友,也可以加我微信,共同探讨!
微信:15011482830 QQ:408917339

6284388 2594 39
最新评论
https://jueru.net/
评 留言
:weixiao:
评 留言
:shuijiao: :weiqu: :zhenbang: :leng:
评 留言
:yiwen: :yiwen: :yiwen: :yiwen:
评 EasySass: could not generate CSS file. See Output panel for details.
这个业务逻辑多少都有点奇怪了,阅读浏览次数增值在新闻详情页的控制器方法里setInc,这怎么还写进模型事件里了。如果非要用onAfterRead也可以,把新闻文章的内容单独分出来一个news_content表,然后把它和news做关联,然后给news_content表的onAfterRead事件做增值处理,这样点进新闻页内查询到文章内容时才会触发它。
评 TP6模型事件-查询后onAfterRead不好用
文章标签更多
ThinkPHP (254)
Mysql (58)
DedeCms (33)
jQuery (67)
证件照 (1)
setInc (4)
setDec (4)
onclick (5)
打开边栏(ESC) 关闭边栏(ESC)
问题:给定一系列可以为空的开始日期和结束日期,优化以下查询的最佳方法是什么(底部的示例模式):
-- Query I am trying to optimize
SELECT * FROM dateranges WHERE
('2014-11-10 05:59:59' > `start` AND '2014-11-03 06:00:00' <= `end`)
OR ('2014-11-03 06:00:00' >= `start` AND `end` is null)
OR ('2014-11-10 05:59:59' <= `end` AND `start` is null);
-- Same query but with placeholders for clarification
SELECT * FROM dateranges WHERE
('{endSearch}' > `start` AND '{startSearch}' <= `end`)
OR ('{startSearch}' >= `start` AND `end` is null)
OR ('{endSearch}' <= `end` AND `start` is null);

实际应用

$rs = Db::name("ad")
			->where("dataFlag=1 and catId='" . $catId . "' and ((startDate<= '$today' and endDate>='$today') or (startDate<= '$today' and endDate='0000-00-00') or (startDate= '0000-00-00' and endDate>='$today') or (startDate= '0000-00-00' and endDate='0000-00-00'))")
			->field('adId,adTitle,adUrl,adImg')
			->order($order)->limit($num)->select();
以后再考虑优化代码的问题

版权声明:本篇文章来源于网络。 来源链接

相关推荐
Mysql 使用AVG聚合函数时,保留两位小数的方法
SQL | 2020-09-28 5072
关于查询最高分、最低分和平均分的 SQL 语句时突然想把 AVG 函数的保留小数设置为两位 SELECT MAX(student_result) AS 最高分,MIN(student_result) AS 最低分,CAST(AVG(student_result) AS DECIMAL(10,2)) AS 平均分 FROM resu...
SQL语句统计每天、每月、每年的数据
SQL | 2017-09-18 4272
1、每年 select year(ordertime) 年, sum(Total) 销售合计 from 订单表 group by year(ordertime) 2、每月 select year(ordertime) 年, month(ordertime) 月, sum(Total) 销售合计 from 订单表 group by yea...
评论:0条
评论加载中...
发表评论