【问题标题】:How to add where column value != 'Trial' in query如何在查询中添加 where 列值!= 'Trial'
【发布时间】:2019-12-13 10:43:18
【问题描述】:

我遇到了一个查询问题,问题是我想选择一个值,其中另一个列值 !=“试用”,我无法做到这一点,请帮助我。

这是我的查询:

$datestart = \DB::table('subscriptions')->where('business_id', $business_id,'payment_transaction_id,""')->Orderby('id','desc')->value('start_date');

【问题讨论】:

  • payment_transaction_id 可以为空吗?如果是的话,你想在它选择的时候选择它吗?

标签: php mysql laravel select where-clause


【解决方案1】:

你需要使用 运算符

->where('column', '<>', 'value')...

【讨论】:

  • $datestart = \DB::table('subscriptions')->where('business_id', $business_id)->WhereNotIn('payment_transaction_id', '' ,'Trial')- >Orderby('id','desc')->value('start_date');还是不行
  • @digisoft 使用 where,而不是 WhereNotIn
【解决方案2】:

你可以使用 '!=' 但它会忽略 NULL 记录,所以使用 '!=' 这个

Model::where('column_name', '!=' ,'value')->orWhereNull('value')->get();

所以安全的是使用''这个操作符,其中字段不为空

Model::where('column_name', '<>' ,'value')->get();

【讨论】:

  • $datestart = \DB::table('subscriptions')->where('business_id', $business_id)->WhereNotIn('payment_transaction_id', '' ,'Trial')- >Orderby('id','desc')->value('start_date');仍然无法正常工作——
  • 只使用 where 而不是 whereNotIn
  • whereNotIn 方法验证给定列的值是否不包含在给定数组中。
  • mysql中&lt;&gt;!=没有区别
【解决方案3】:

你需要这个操作符在哪里

...->where('column_name', '<>' ,'value')->...

【讨论】:

  • 点评来源: 嗨,这篇文章似乎没有为问题提供quality answer。请编辑您的答案并改进它,或者将其作为评论发布。
猜你喜欢
  • 1970-01-01
  • 2012-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-04
  • 1970-01-01
  • 1970-01-01
  • 2020-01-22
相关资源
最近更新 更多