php - 如何在 PHP mongodb 驱动程序中比较 mongodb 中同一表的 2 列?
问题描述
请通过检查以下示例为我提供对我的问题的准确答案:
比如表:员工有字段(age1,age2)
我想做 SELECT 查询
Select count(*) From Employees Where age1 < age2
如何在mongodb
php 驱动程序功能中做到这一点?
解决方案
尝试以下操作:-
$db->empoyees->find( array('$where' => 'this.age1 < this.age2' ) );
或者
$db->empoyees->find(array('age1' => array('$lt' => 'age2')));
推荐阅读
- ios - 使用 .onDelete -SwiftUI 时索引超出范围
- sql - 获取每个组的第一条和最后一条记录
- google-chrome - 如何检索检查元素中的隐藏元素 - Chrome 开发工具?
- python - Numpy Python 等效于 MATLAB corr
- raspberry-pi - 如何将 LOLIN 7 WS2812B LED 连接到 Raspberry Pi Pico (RP2040)?
- mysql - 数据库中的成功快照表。但是当有事件插入、更新或删除时不能CDC
- java - java - 如何将Gson与Java中可以是多种类型的对象一起使用?
- amazon-web-services - 将 Dotnet 核心 Web api 部署到 AWS EKS
- autohotkey - 使用打开文件对话框的文件名字段打开多个文件?
- reactjs - 如何将 3 个输入元素中的单个输入元素传递给反应钩子中的组件