我有下图所示的表格,我想计算多年来发生的所有新代码,例如Year 1972 : New Code: 4, 30 times, New Code: 5 60 times
Year 1857 New Code: 4, 30 times, New Code: 5, 60 times
。
最好将结果保存在第1列中。
答案 0 :(得分:1)
可以这么简单:
select Year
, NewCode
, count(*)
from YourTable
group by
Year
, NewCode
如果您想更新表格:
update YourTable yt1
set Column1 =
(
select count(*)
from YourTable yt2
where yt1.Year = yt2.Year
and yt1.NewCode = yt2.NewCode
)