我有未运行下面的查询使用WITH子句:如何一起选择与WHERE子句
with countf as (
select nationid, count(*) as c from customer
group by nationid
),
maxf as (select max(nationid) from customer)
select c.customerid, c.nationid from customer c, countf cf, maxf m
where c.nationid = cf.nationid
and cf.c = m
这个问题似乎是m
是一个记录,而不是一个整数。但是,如果我将它作为子查询运行如下:
cf.c = (select max(nationid) from customer)
它按预期工作。我认为我正在使用with语句而不是预期的方式。试图
cf.c in maxf
让我假设使用WITH
只是不应该在一个WHERE
子句中使用生成的表。
我知道还有其他方法可以使用all
来获得相同的查询。我真的只对我应该如何使用with语句感兴趣。我以后只能使用它到SELECT
吗?
在此先感谢您提供任何帮助。
另外,您正在使用的连接语法应该是hav e已经死亡。如果您使用显式连接语法 – JohnHC
@JohnHC指出,那么您可能会发现这个世界是一个更好的地方,感谢您的支持。我从来没有真正使用SQL,但我更愿意写在考试纸上,所以我尽量保持简单:) – lbrndnr