繁体   English   中英

在一个表内执行postgresql操作,并从同一表中操作得出的两个不同结果中查找结果

[英]postgresql operation within a table and find result from two different result from operating in same table

我在这里使用PostgreSQL
这是我的表格“ num”中的一个字段:
adsh :一些带有破折号的数字,例如(1234-23456-456789)
tag :字符,例如(ReturnOnAsset)
version :可以是以下两种格式之一:1.与adsh完全相同。2. us-gaap / yyyy,例如。 (us-gaap / 2009)
还有其他一栏,但并不重要
主键是上方的3列,而其他一些列则组合在一起。
对于每个ad​​sh,有几个版本值us-gaap / dei / invest + yyyy或还请记住,此表中有10 ^ 8个元组

第一步: select tag, version from num where version=adsh as result a
第二步: select adsh, version from num where version!=adsh as result b
第三步: select tag, b.version from a, b where a.version=b.adsh

我想知道是否可以暂时保存前两个步骤的结果以便执行第三步。 我可以那样做吗? 最有效的方法是什么?

谢谢!

我发现使用with子句的解决方案:

with a as (select tag, version from num where version=adsh), b as (select adsh, version from num where version!=adsh) select tag, b.version from a, b where a.version=b.adsh; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM