首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据单表中的两个字段求值

根据单表中的两个字段求值
EN

Stack Overflow用户
提问于 2020-06-02 09:45:07
回答 1查看 31关注 0票数 0

我有一个具有以下字段的表用户。

代码语言:javascript
复制
 id user_name   team       onsite_offshore 
 1   xxx        US East     offshore
 2   YYY        US East     onsite
 3   zzz        US East     onsite
 4   aaa        Us West     onsite
 5   bbb        US West     offshore

我有两个依赖的下拉地理和地理位置,地理值'US East‘和'US West’,位置值'US East‘和’US East‘的前提是’US East‘

“美国西部和前提”的意思是“美国西部”。

地质定位

美国东部-美国东部,近海(逐个显示为2个选项),美国西部-美国西部和近海(逐个显示为2个选项)

代码语言:javascript
复制
  on choosing US East in localtion  with geo 'US East' dropdow I want to load the value 'yyy,zzz' which is not inluded in offshore(which is in same table with different column.)
       on choosing offshore in localtion dropdown for geo 'US EASt'I want to load the value 'XXX' which is should inluded in offshore(which is in same table with different column.)

  on choosing US West in localtion  with geo 'US West' dropdown I want to load the value 'aaa' which is not inluded in offshore(which is in same table with different column.)
       on choosing offshore in localtion dropdown for geo 'US West' I want to load the value 'bbb' which is should inluded in offshore(which is in same table with different column.)

$filter_team_details=DB::table('user_master')->leftjoin('user_teams','user_teams.team','=','user_master.geo')->whereIn('user_teams.team',$teams)->groupBy('user_teams.team')->pluck('user_teams.team')->toArray(); (In this query I want to check for onsite_offshore condition in same query )

是否可以将两个条件单表检查为

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-02 11:05:36

我不知道为什么要使用whereIn,您的查询可以这样简单地为多个条件编写:

代码语言:javascript
复制
    $filter_team_details = DB::table('user_master')
                           ->leftjoin('user_teams','user_teams.team','=','user_master.geo')
                           ->where('user_teams.team',$teams)
                           ->where('user_teams.onsite_offshore',$nameOfyourVariable)
                           ->groupBy('user_teams.team')
                           ->pluck('user_teams.team')
                           ->toArray();

尽管您可以使用whereIn (如果您愿意,我希望它对您有帮助:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62149175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档