select case when cntrctr_lcns_seq_no is null
then 1
else max(cntrctr_lcns_seq_no)
end as cntrctr_lcns_seq_no
from nuwmsweb.cntrctr_lcns_info
where third_party_id = thirdPartyId
group by third_party_id
我想你看看我想做什麼。獲取特定ID的max seq_no。但是我得到錯誤「不是一個小組小組條款」。甲骨文 - 最大案例
此選擇語句是較大插入的一部分。
謝謝!
更新:這是整個聲明
insert into nuwmsweb.CNTRCTR_LCNS_INFO
(third_party_id,cntrctr_lcns_seq_no,cntrctr_lcns_no,
lcns_st_cd,certfn_level_type_cd,cntrctr_type_cd,cut_tap_authy_ind,
stat_type_nm)
VALUES(thirdPartyId,(select max(case when cntrctr_lcns_seq_no is null
then 1
else cntrctr_lcns_seq_no
end) as cntrctr_lcns_seq_no
from nuwmsweb.cntrctr_lcns_info
where third_party_id = thirdPartyId
group by third_party_id
),
licenseNumber,licenseState,licenseLevel,licenseType,cutTap,status);
不完全,我實際上想要1返回,如果表中還沒有一個id。 – kralco626 2011-03-07 14:59:00
夠公平,只需將它包裹在一起。看我的編輯。 – 2011-03-07 15:04:28
不確定什麼樣的coalsce ......但是它起作用,如果我從nuwmsweb.cntrctr_lcns_info中選擇coalesce(max(cntrctr_lcns_seq_no)+ 1,1)作爲cntrctr_lcns_seq_no,其中third_party_id = thirdPartyId'注意我試過的'+ 1' – kralco626 2011-03-08 11:21:44