gpt4 book ai didi

sql - 如何在 sql 查询中使用两个连接?句法

转载 作者:搜寻专家 更新时间:2023-10-30 22:11:50 24 4
gpt4 key购买 nike

很抱歉问这样一个新手问题,但我一直在尝试理解这个 SQL 查询并添加一个东西,但我无法做到这一点。

这里是查询:

select 
p.id, p.nick, p.creation_date
from
tb_player p
left outer join
tb_invoice i on (i.player_id = p.id), tb_player_last_login tpl
where
p.creation_date < now() - '12 months'::interval
and tpl.last_login_date < now() - '12 months'::interval
and tpl.player_id = p.id
and p.id > 9999
and (p.email = 'EDITE-SEU-EMAIL' or p.email = 'configure-seu-email')
and i.id is null
limit 15000;

所以我要从这个 tb_player 中选择一组人,我有另一个名为 tb_email_list 的表,我需要在某个地方说包括 的玩家tb_player 具有与有效的 tb_email_list 相同的电子邮件。

  • tb_player 有昵称和电子邮件训练营
  • tb_email_list player_id, email, is_valid

我尝试加入一些连接,但似乎没有任何效果......

请帮忙?

我的 friend 帮了我,事情就这样

select p.id, p.nick, p.creation_date 
from tb_player_last_login tpl, tb_player p
left outer join tb_invoice i on (i.player_id = p.id)
left join tb_email_list e on e.player_id = p.id
where p.creation_date < now() - '12 months'::interval
and tpl.last_login_date < now() - '12 months'::interval
and tpl.player_id = p.id
and p.id > 9999
and (p.email = 'EDITE-SEU-EMAIL' or p.email = 'configure-seu-email' or e.is_valid = -1)
and i.id is null
limit 15000

感谢帮助

最佳答案

您只需添加另一个 join 子句:

select p.id, p.nick, p.creation_date 
from tb_player p
left outer join tb_invoice i on i.player_id = p.id
left outer join tb_player_last_login tpl on tpl.player_id = p.id --here
where p.creation_date < now() - '12 months'::interval
and tpl.last_login_date < now() - '12 months'::interval
and p.id > 9999
and (p.email = 'EDITE-SEU-EMAIL' or p.email = 'configure-seu-email')
and i.id is null
limit 15000;

关于sql - 如何在 sql 查询中使用两个连接?句法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26104637/

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