0

我需要加入表“客户”和表“评论”。我想从“客户”表中找出 2021 年 3 月 24 日创建的帐户。随后,在“comment”表的“comment_desc”列中过滤那些没有“休眠”字样的帐户。参考我的 SQL、表格和预期结果:

My SQL:
Select customer.account, customer.creation_date, customer.country 
From DATABASE.customer, DATABASE.comment
Where customer.account=comment.account
And customer.creation_date = '03/24/2021'
And comment.comment_desc not like '%Dormant%'

Table 1: Customer
account | creation_date | country
1111111 | 24/3/2021     | AU
2222222 | 25/3/2021     | NZ
3333333 | 24/3/2021     | AU
4444444 | 24/3/2021     | AU
5555555 | 24/3/2021     | NZ

Table 2: Comment
account | comment_date  | comment_desc
1111111 | 24/3/2021     | newly created
1111111 | 24/3/2021     | callback
1111111 | 25/3/2021     | Update rate
1111111 | 25/3/2021     | Sales follow up
2222222 | 25/3/2021     | newly created
2222222 | 25/3/2021     | Sales follow up
2222222 | 25/3/2021     | Update rate
3333333 | 24/3/2021     | callback
3333333 | 25/3/2021     | manual Dormant
4444444 | 24/3/2021     | Update rate
4444444 | 24/3/2021     | Update account info
4444444 | 24/3/2021     | Sales follow up
5555555 | 24/3/2021     | Update rate
5555555 | 24/3/2021     | Dormant entry

Expected Result:
account  | creation_date | country
1111111  | 24/3/2021     | AU
4444444  | 24/3/2021     | AU

请协助建议我应该如何修改/改进我的 SQL。

4

1 回答 1

0

你可以做:

select *
from customer
where creation_date = '03/24/2021'
  and account not in (
    select account from comment where comment_desc like '%Dormant%'
  )
于 2021-03-26T02:23:02.017 回答