首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

求一句SQL语句,该如何处理

2012-01-28 
求一句SQL语句我有一个物品表table1id(唯一)名称1name12name23name34name4还有一个表table2id(上面的外键)

求一句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;

热点排行