gpt4 book ai didi

yii - yii2 中的 LEFT join AND 命令

转载 作者:行者123 更新时间:2023-12-04 19:17:29 25 4
gpt4 key购买 nike

我想在 yii2 中写一个查询
我不知道怎么写
我从文档中尝试了一些东西,但它不起作用
这是我的查询

SELECT notification.*,event.title,user.firstname,user.lastname FROM notification 
LEFT JOIN event ON event.id = notification.source_id
AND notification.activity_type = "checkin"
Where user.firstname in (select id from user where user_id=1)
LEFT JOIN user ON user.id = notification.source_id
AND notification.activity_type = "friend"
Where user.firstname in (select id from user where user_id=1)

这是我现在编写的查询,我需要添加 AND 函数,就像它在查询中一样
    $query  ->select(['notification.*,event.title,user.firstname,user.lastname'])
->from('notification')
->leftJoin('event', 'event.id = notification.source_id')
->leftJoin('user', 'user.id = notification.source_id');

最佳答案

您是否尝试过以下操作:

$query  ->select(['notification.*,event.title,user.firstname,user.lastname'])
->from('notification')
->leftJoin('event', 'event.id = notification.source_id AND notification.activity_type = "checkin" ')
->leftJoin('user', 'user.id = notification.source_id AND notification.activity_type = "friend"');

关于yii - yii2 中的 LEFT join AND 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33092919/

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