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