简体   繁体   中英

cakePHP - Join with conditional virtual field

Is there a way I can generate this query with 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

What I want to return is the alias field SyncProcessed based on the condition

I'v tried using joins but couldn't get this result

您可以通过以下方式使用自定义查询:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM