这是昨天求职。一个坛友发的:
update m_my_special set m_videonum=isnull(b.rownum,0)
from m_my_special as a inner join (select m_uid,m_specialid,isnull(count(0),0) as rownum from m_data group by m_uid,m_specialid) as b on a.m_uid=b.m_uid and b.m_specialid=a.m_id And a.m_uid = 2
update m_my_special set m_videonum=isnull(b.rownum,0)
from m_my_special as a left join (select m_uid,m_specialid,isnull(count(0),0) as rownum from m_data group by m_uid,m_specialid) as b on a.m_uid=b.m_uid and b.m_specialid=a.m_id And a.m_uid = 2
UPDATE a
SET m_videonum=(SELECT COUNT(1) FROM m_data WHERE m_uid=a.m_uid AND m_specialid=a.m_id)
FROM m_my_special AS a
WHERE EXISTS(SELECT 1 FROM m_data AS x
WHERE x.m_uid=a.m_uid
)