我有下表
ID | AreaPath | IterationPath |
1 Area1 Iteration1
2 Area2 Iteration1
2 Area2 Iteration2我只想在ID列上使用计数。
想要的产出应该是:
CountID | ID | AreaPath | IterationPath |
1 1 Area1 Iteration1
2 2 Area2 Iteration1
2 2 Area2 Iteration2以下查询:
select
count(TRV.ID ) as CountID,
TRV.ID,
TRV.AreaPath,
TRV.IterationPath
FROM table TRV
Group BY AreaPath, IterationPath 给出以下输出:
CountID | ID | AreaPath | IterationPath |
1 1 Area1 Iteration1
1 2 Area2 Iteration1
1 2 Area2 Iteration2我应该如何更改它以获得想要的输出?
发布于 2014-07-01 17:03:50
在除MySQL之外的所有四大数据库中:
SELECT COUNT(*) OVER (PARTITION BY id) cnt,
m.*
FROM mytable m在MySQL中:
SELECT (
SELECT COUNT(*)
FROM mytable mi
WHERE mi.id = m.id
) cnt,
m.*
FROM mytable mhttps://stackoverflow.com/questions/24515672
复制相似问题