thinkphp:数据库查询操作四:(①查询某列的值等于一变量,且另一列的数据不是为零就是为空(多条件查询),②whereRaw(查询某列的值大于另一列的值))

 一、查询一个列的数值等于一个变量,并且另外一列的数据不是为零就是为空

查询表wip_operation_plan,

当列wip_entity_name为变量$wip_entity_name

并且另外一列begin_quantity为空,或者为0

查询满上述条件的operation_code列的所有值


$data = Db::table('wip_operation_plan')
      ->where(['wip_entity_name'=>$wip_entity_name])
      ->where(function ($query) {
        $query->where('begin_quantity',null)
        ->whereOr('begin_quantity','=',0); // 判断另外一列是否为0
       })
      ->column('operation_code');

二、查询条件单行满足:一列的数值大于另外一列的数值

对表wip_operation_plan进行查询条件有:

①表中数据begin_quantity类要大于input_quantity这一列的值

②wip_entity_name等于变量$wip_entity_name


Db::table('wip_operation_plan')
->whereRaw('begin_quantity > input_quantity')
->where(['wip_entity_name' => $wip_entity_name])
->select();

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值