php - 如何加入“IN”结果并检查“where” active = 1?
问题描述
在我的查询中,我检查是否tokens.id
存在于dapp_tokens
. 我想补充一点,结果dapp_tokens
也必须active = 1
在dapps
表格中。
所以我需要加入在中找到dapps
的行的表,但是如何在 Raw SQL 中做到这一点?tokens.id
dapp_tokens
$data['tokens'] = Token::where('active', 1)
->whereRaw('tokens.id in (select token_id from dapp_tokens where active = ?)', [1])
->sortable('market_cap')
->orderby('id','desc')
->paginate($page_count);
解决方案
我试过这个,但我只能用“IN”获得 1 col 值:
基数违规:1241 操作数应包含 1 列
$data['tokens'] = Token::where('tokens.active', 1)
->whereRaw('tokens.id in (select token_id, dapp_id from dapp_tokens LEFT JOIN dapps ON dapps.id = dapp_id where dapps.active = ?)', [1])
->sortable('market_cap')->orderby('id','desc')->paginate($page_count);
编辑:好像我已经有了解决方案,只需要从 whereRaw 的选择器中删除 dapp_id
推荐阅读
- elasticsearch - 如何找出 Elasticsearch 集群中的空闲节点?
- angularjs - 如果我不将我的 angularjs 代码迁移到 angular 2 会发生什么
- python-3.x - 在python中对元组进行排序并保持相对顺序
- java - 如何搜索内存地址
- python - 当我在 kaggle 的 notebook 中使用 pandas 多次读取 csv 文件时发生了什么?
- python - 如何在 pyspark 中读取简单的字符串文本文件?
- mysql - 如何正确使用 group_concat 连接 MYSQL 中的 Join 查询结果?
- vim - 如何为vi中制作的文件自动制作Shebang行?
- gitlab - 如何让gitlab故意重试?
- c# - 从目录中按章节拆分 PDF