Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在汇总数据,我无法对某些列求和,所以我想从该列中获取最频繁的观察值或中值。示例如下,在此先感谢。
身份证网站
1 3
1 2
2 4
2 5
我希望它看起来像
WITH temp AS( SELECT ID, Site, COUNT(*) As counts FROM id_table GROUP BY ID, Site ) SELECT temp.ID, temp.Site FROM temp JOIN (SELECT ID, MAX(counts) max_counts FROM temp GROUP BY ID )b ON temp.ID = b.ID AND temp.counts = b.max_counts ORDER BY ID ASC
SQL小提琴