sql server - sql update with aggregate functions in where clause -


i have table these fields >>>

i want number of s-id=1 >>>>relevancy value updated 2

(s-id)(relevancy) 0         null 0         null 3         2 4         null 4         null 4         null 4         null 5         2 9         null 

here code:

    select s-id,count(s-id) ccc     group s-id      update ccc set relevancy=2 count(s-id)=1 

but figured aggregate function can't used in clause,what should now?

update ccc set relevancy = 2  (select count(*) ccc c2 c2.[s-id] = ccc.[s-id])  = 1 

demo (last row's relevancy updated 2 since 9 unique)

another option using cte count(*)over:

with cte (     select [s-id], relevancy,            cnt = count(*) on (partition [s-id])     ccc ) update cte set relevancy = 2 cnt = 1 

demo


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -