mysql - Count number of times, a number appears and update it to a different column -
i not sure how in mysql, have searched can't seem find solution. , have table so.
id pid occurrence 1 23 blank 2 23 blank 3 44 blank
basically, occurrence should have value of 2, id 1,2 , value of 1 id 3. appreciated. can call count , group by, , number of times each 1 occurance, update column occurrence in right place each pid.
to correct occurrence
value can do
select pid, count(*) occurrence your_table group pid
to update table do
update your_table t1 join ( select pid, count(*) occurrence your_table group pid ) t2 on t1.pid = t2.pid set t1.occurrence = t2.occurrence
Comments
Post a Comment