我有這些表:
table "articles_description" (a)
code desc
1 article1
2 article2
3 article3
table "articles_type" (b)
code value
1 inf
1 def
2 inf
3 inf
我需要從表 b 中僅獲取僅獲取的代碼值,并且僅獲取具有“inf”值的一行(在示例中,我需要將代碼 2 和 3 傳遞給游標)以獲取隱式游標中的值回圈(下一個代碼是 FOR reg IN c_cur LOOP ... END LOOP;)。
這是隱式游標:
cursor c_cur is
select a.*
from articles_description a,
articles_type b
where a.code = b.code
and b.value = 'inf'; --(only need to get the article code that has 1 row with 'inf' value)
我試圖構建一個函式來回傳文章代碼,但在這種型別的游標中不起作用,并且要求強制以這種方式構建。
uj5u.com熱心網友回復:
select "code"
from b join a using("code")
group by "code"
having count(*) < 2
and max("value") = 'inf'
| 代碼 |
|---|
| 2 |
| 3 |
小提琴
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/510548.html
