求一句SQL语句
我有一个物品表
table1
id(唯一) 名称
1 name1
2 name2
3 name3
4 name4
还有一个表table2
id(上面的外键)
4
3
3
4
2
1
1
4
3
3
4
2
2
1
3
2
1
4
求table2中按id出现次数最多的一位
------解决方案--------------------select top 1 count(id),id from table2 group by 2
------解决方案--------------------帮顶
------解决方案--------------------select max(name) from table1 t1,table2 where t1.id = t2.id
------解决方案--------------------select t1.name from (select id,count(id) as num from t2 group by id) t,t1 where t.num=(select max(num) from (select id,count(id) as num from t2 group by id) t) and t1.id=t.id
------解决方案--------------------select name from table where id=(select top 1 count(id) from table2 order by count(id) desc)
------解决方案--------------------select table1.name from (select id,count(id) as num from table2 group by id) t,table1
where t.num=(select max(num) from (select count(id) as num from table2 group by id) t) and table1.id=t.id;