使用子查詢時應當注意的

2022-04-04 04:27:34 字數 1246 閱讀 1210

在乙個查詢中:

update a

set a.scts = b.v1, a.ycyl = b.v2, a.ycsl = b.v3

from kfdbsyy a,

(select f_wellnumber, count(*) as v1, sum(f_fule) as v2,

sum(f_totalliquid - f_fule) as v3

from (select *

from cy_wellrecord

where f_reporttime like '2004-06%') 

group by f_wellnumber) b

where a.jh = b.f_wellnumber and a.ny = '200406'

紅色在子查詢單獨執行沒有問題,但整個執行,老是報告group附近有錯。反覆試驗,發現跟內部的子查詢有關。改為

update a

set a.scts = b.v1, a.ycyl = b.v2, a.ycsl = b.v3

from kfdbsyy a,

(select f_wellnumber, count(*) as v1, sum(f_fule) as v2,

sum(f_totalliquid - f_fule) as v3

from (select *

from cy_wellrecord

where f_reporttime like '2004-06%')  as c

group by c.f_wellnumber) b

where a.jh = b.f_wellnumber and a.ny = '200406'

或者update a

set a.scts = b.v1, a.ycyl = b.v2, a.ycsl = b.v3

from kfdbsyy a,

(select f_wellnumber, count(*) as v1, sum(f_fule) as v2,

sum(f_totalliquid - f_fule) as v3

from (select *

from cy_wellrecord

where f_reporttime like '2004-06%') derivedtbl

group by f_wellnumber) b

where a.jh = b.f_wellnumber and a.ny = '200406'

均可。

當C 使用引用傳遞引數時,應當注意的問題

如果實參與引用引數不匹配,c 將生成臨時變數。如果引用引數是const,則編譯器在下面兩種情況下生成臨時變數 實參型別是正確的,但不是左值 實參型別不正確,但可以轉換為正確的型別 左值引數是可被引用的資料物件,例如,變數 陣列元素 結構成員 引用和被解除引用的指標都是左值,非左值包括字面常量和包含多...

mybatis中使用in查詢時的注意事項

1.當查詢的引數只有乙個時 findbyids listids 1.a 如果引數的型別是list,則在使用時,collection屬性要必須指定為 list findbyidsmap resultmap baseresultmap select base column list from jria ...

mybatis中使用in查詢時的注意事項

1.當查詢的引數只有乙個時 findbyids listids 1.a 如果引數的型別是list,則在使用時,collection屬性要必須指定為 list id findbyidsmap resultmap baseresultmap select refid base column list f...