[英]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列,而其他一些列則組合在一起。
對於每個adsh,有幾個版本值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.