在Teradata中,我如何使用所选列的子集来满足“哪里存在”子句

问题描述 投票:0回答:1

因此,假设我有一个包含以下各列的表(用户):

名字|姓|年龄|价值|费用

是否有一种方法可以重构此查询,以使我的所有行的所有列都都存在于“ where exist”子查询中的姓氏和姓氏?

Select * from users u 
where exists (
    select firstname, surname from users u2
    where age = 20
)
sql teradata exists teradata-sql-assistant
1个回答
0
投票

假设select * from users where age = 20由于某种原因无法正常工作,我想您正在寻找类似这样的内容:

select
*
from
users u
where exists
(select * from users where age = 20 and u.first_name = first_name and u.last_name = last_name)

您最好加入关键列,如果它们存在的话。您可以在子查询中为表加上别名,并限定那里的列,但不必这样做。

© www.soinside.com 2019 - 2024. All rights reserved.