select count 函数的应用

winsonink 2011-11-22 01:40:50
表大概是这样的,
id name county
1 tracy 日本
2 john 美国
3 sam 日本
4 revoke 德国
5 mine 美国

查询存在相同的国家的人物信息

id name county
1 tracy 日本
2 john 美国
3 sam 日本
5 mine 美国
...全文
72 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
winsonink 2011-11-24
  • 打赏
  • 举报
回复
国家是一张独立的表,不能直接group by。。。
raymonshi 2011-11-22
  • 打赏
  • 举报
回复
select * from [tb] where [county] in(select [county] from tb group by [county] having count(*)>1)
觉得这个思路比较好
黄_瓜 2011-11-22
  • 打赏
  • 举报
回复
--count


select * from [tb] where [county] in(select [county] from tb group by [county] having count(*)>1)
geniuswjt 2011-11-22
  • 打赏
  • 举报
回复
被秒了,路过
-晴天 2011-11-22
  • 打赏
  • 举报
回复
select * from tb a
where exists(select 1 from tb where name<>a.name and county=a.county)
黄_瓜 2011-11-22
  • 打赏
  • 举报
回复
select * from table1 as a where exists(select 1 from table1 where county=a.county and ID<>a.ID)
中国风 2011-11-22
  • 打赏
  • 举报
回复
or
select * from table1 as a where exists(select 1 from table1 where county=a.county and name <>a.name )
中国风 2011-11-22
  • 打赏
  • 举报
回复
select * from table1 as a where exists(select 1 from table1 where county=a.county and ID<>a.ID)

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧