2015-11-23 70 views
1

我一直在嘗試下面的SQL查詢到警予基於活動記錄的查詢與andWhere但沒有運氣轉換轉換SQL哪裏CASE查詢Yii2活動記錄

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')) 
+0

你有多遠?什麼是錯誤信息? – topher

回答

1

如果「用戶」表是由用戶代表class model:

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(); 
+0

感謝@ fabrizio-caldarelli的工作原理。 – Hoshomoh