惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
N
News and Events Feed by Topic
Recent Announcements
Recent Announcements
D
Docker
M
MIT News - Artificial intelligence
L
LangChain Blog
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
博客园_首页
MongoDB | Blog
MongoDB | Blog
美团技术团队
S
Schneier on Security
G
GRAHAM CLULEY
月光博客
月光博客
有赞技术团队
有赞技术团队
Vercel News
Vercel News
Scott Helme
Scott Helme
P
Privacy International News Feed
Last Week in AI
Last Week in AI
Recorded Future
Recorded Future
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
Attack and Defense Labs
Attack and Defense Labs
Google Online Security Blog
Google Online Security Blog
Simon Willison's Weblog
Simon Willison's Weblog
量子位
S
Security @ Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
V
Visual Studio Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
NISL@THU
NISL@THU
N
Netflix TechBlog - Medium
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
罗磊的独立博客
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Threatpost
L
Lohrmann on Cybersecurity
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Security Affairs
Cloudbric
Cloudbric
爱范儿
爱范儿
H
Heimdal Security Blog
PCI Perspectives
PCI Perspectives

博客园 - Tinywan

响应错误: Indirect modification of overloaded element of app\model\StudentCacheModel has no effect - Tinywan Ubuntu 22.04 编译安装 PHP 7.4.33 报错:make: *** [Makefile:749: ext/openssl/openssl.lo] Error 1 how to set mpdf HTML contains invalid UTF-8 character(s) 和 CPU 100% Redis Docekr WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition Nginx添加第三方模块,出现“is not binary compatible in”错误的解决方案 Docker 数据库连接见解异常 SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again 解决mysql死锁问题 SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction Java系列 | 如何讲自己的JAR包上传至阿里云maven私有仓库【云效制品仓库】 Redis系列 | 分类树查询功能如何从2s优化到0.1s Docker系列 | docker endpoint for “default” not found Node系列 | Node版本管理工具 fnm Java系列 | IntelliJ IDEA 如何导入和使用一个Jar包 Chrome扩展插件:Console Importer(控制台导入器) PHP系列 | mPdf字体库异常 Cannot find TTF TrueType font file "Eeyek.ttf" in configured font directories PHP系列 | PHP中的stdClass是什么? 网络安全 | 记录一次acme.sh更新证书 Error add txt for domain:_acme-challenge.tinywan.com 大数据系列 | 阿里云datav数据可视化(使用json文件生成可视化动态图标) Docker系列 | SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again768 Java系列 | Linux系统中运行JMeter脚本
PHP系列 | TP6使用表达式设置数据 Db::raw('end_time')
Tinywan · 2022-04-22 · via 博客园 - Tinywan

模型或者Db无数据

使用以下语句查询记录

$liveList = Db::table('sys_live')
    ->field('id,begin_time,end_time,title')
    ->where('end_time','<>',0)
    ->where('begin_time','>','end_time')
    ->count();

查询结果为:0

通过fetchSql打印SQL语句

$liveList = Db::table('sys_live')
    ->field('id,begin_time,end_time,title')
    ->where('end_time','<>',0)
    ->where('begin_time','>','end_time')
    ->fetchSql()
    ->count();

打印SQL如下

SELECT COUNT(*) AS think_count FROM `sys_live` WHERE  `end_time` <> 0  AND `begin_time` > end_time

注意:细心的朋友会发现开始时间是:`begin_time`(有双引号),而结束时间是:end_time(无双引号)

直接通过MySQL命令行,执行以上SQL语句是没问题的

mysql> SELECT COUNT(*) AS think_count FROM `sys_live` WHERE  `end_time` <> 0  AND `begin_time` > end_time;
+-------------+
| think_count |
+-------------+
|        100  |
+-------------+
1 row in set (0.14 sec)

解决办法

查询条件使用表达式设置数据 Db::raw('end_time'),最后改写为以下查询

$liveList = Db::table('sys_live')
    ->field('id,begin_time,end_time,title')
    ->where('end_time','<>',0)
    ->where('begin_time','>',Db::raw('end_time'))
    ->count();