Mysql 计算次数,出现一个数字并将其更新到其他列

Mysql 计算次数,出现一个数字并将其更新到其他列,mysql,Mysql,我不知道如何在mysql中做到这一点,我已经搜索过了,但似乎找不到解决方案。 , 我有一张这样的桌子 id pid occurrence 1 23 blank 2 23 blank 3 44 blank 基本上,对于id 1,2,事件的值应为2,对于id 3,事件的值应为1。 任何帮助都将不胜感激。我可以很容易地调用count和GROUP BY,并获得每次出现的次数,但我想为每个pid在正确的位置更新列出现次数。要获得正确的出现次数值,您可以执行以下操作 select pid

我不知道如何在mysql中做到这一点,我已经搜索过了,但似乎找不到解决方案。 , 我有一张这样的桌子

id pid occurrence  
1  23  blank
2  23  blank
3  44  blank
基本上,对于id 1,2,事件的值应为2,对于id 3,事件的值应为1。
任何帮助都将不胜感激。我可以很容易地调用count和GROUP BY,并获得每次出现的次数,但我想为每个pid在正确的位置更新列出现次数。

要获得正确的
出现次数
值,您可以执行以下操作

select pid, count(*) as occurrence
from your_table
group by pid
要更新表,请执行以下操作:

update your_table t1
join 
(
    select pid, count(*) as occurrence
    from your_table
    group by pid
) t2 on t1.pid = t2.pid
set t1.occurrence = t2.occurrence

要获得正确的
出现次数
值,可以执行以下操作

select pid, count(*) as occurrence
from your_table
group by pid
要更新表,请执行以下操作:

update your_table t1
join 
(
    select pid, count(*) as occurrence
    from your_table
    group by pid
) t2 on t1.pid = t2.pid
set t1.occurrence = t2.occurrence

要获得正确的
出现次数
值,可以执行以下操作

select pid, count(*) as occurrence
from your_table
group by pid
要更新表,请执行以下操作:

update your_table t1
join 
(
    select pid, count(*) as occurrence
    from your_table
    group by pid
) t2 on t1.pid = t2.pid
set t1.occurrence = t2.occurrence

要获得正确的
出现次数
值,可以执行以下操作

select pid, count(*) as occurrence
from your_table
group by pid
要更新表,请执行以下操作:

update your_table t1
join 
(
    select pid, count(*) as occurrence
    from your_table
    group by pid
) t2 on t1.pid = t2.pid
set t1.occurrence = t2.occurrence

如果要在表中设置值,请将
update
join
一起使用:

update table t join
       (select pid, count(*) as cnt
        from table 
        group by pid
       ) tt
       on tt.pid = t.pid
    set t.occurrence = tt.cnt;

如果要在表中设置值,请将
update
join
一起使用:

update table t join
       (select pid, count(*) as cnt
        from table 
        group by pid
       ) tt
       on tt.pid = t.pid
    set t.occurrence = tt.cnt;

如果要在表中设置值,请将
update
join
一起使用:

update table t join
       (select pid, count(*) as cnt
        from table 
        group by pid
       ) tt
       on tt.pid = t.pid
    set t.occurrence = tt.cnt;

如果要在表中设置值,请将
update
join
一起使用:

update table t join
       (select pid, count(*) as cnt
        from table 
        group by pid
       ) tt
       on tt.pid = t.pid
    set t.occurrence = tt.cnt;