cakePHP - 加入条件虚拟字段

时间:2014-11-13 16:49:42

标签: mysql cakephp join

有没有办法用cakePHP生成这个查询:

SELECT pl.zban_player_id 'Player', pl.display_info 'GUID', pl.source_group 'Source',     
IF(pv.variable_value is not null, 1,0) as  SyncProcessed
FROM banner_key_current bkc
INNER JOIN banner_key_current_ext bkce ON bkc.banner_key_id = bkce.banner_key_id
INNER JOIN operations op ON op.operation_id = bkc.operation_id
INNER JOIN players pl ON pl.zban_player_id = bkce.identifier
INNER JOIN playermap_now pmn ON pmn.zban_player_id = pl.zban_player_id
LEFT JOIN player_variables pv ON (pv.zban_player_id = pl.zban_player_id AND pv.variable_name = 'player_sync_processed')
WHERE bkc.date BETWEEN '2014-05-01' AND '2014-11-13'
AND op.category = 117
AND pmn.user_id IN (1)
Group By bkce.identifier

我想要返回的是基于条件

的别名字段SyncProcessed

我尝试使用联接,但无法获得此结果

1 个答案:

答案 0 :(得分:0)

您可以使用以下命令来使用自定义查询:

$this->YourModel->query('your query here')