gpt4 book ai didi

php - 将 SQL where CASE 查询转换为 Yii2 Active Record

转载 作者:行者123 更新时间:2023-11-29 06:19:54 24 4
gpt4 key购买 nike

我一直在尝试使用 andWhere 将下面的 SQL 查询转换为基于 yii 的事件记录查询,但没有成功

SELECT * FROM `users` 
WHERE `role` = 1
AND (CASE users.type WHEN 'admin' THEN users.admin_id ELSE users.member_id END IN ('94', '56', '173', '172', '50', '67', '57', '86', '53', '93', '39', '40', '171', '175', '136', '160', '145', '177', '156', '88', '125', '176', '157', '120', '165', '116', '103', '107', '149', '134', '146', '92', '164', '82', '148', '111', '78', '77', '151', '87', '129',, '29', '62'))

最佳答案

如果 'users' 表由用户类模型表示:

User::find()->where(['role' => 1'])->andWhere("(CASE users.type WHEN 'admin' THEN users.admin_id ELSE users.member_id END IN ('94', '56', '173', '172', '50', '67', '57', '86', '53', '93', '39', '40', '171', '175', '136', '160', '145', '177', '156', '88', '125', '176', '157', '120', '165', '116', '103', '107', '149', '134', '146', '92', '164', '82', '148', '111', '78', '77', '151', '87', '129',, '29', '62'))")->all();

关于php - 将 SQL where CASE 查询转换为 Yii2 Active Record,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33868026/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com