求一个sql语句

mengshan1986 2008-07-29 11:09:57
有两个表
第一个表
tid fid
第二个表
tid information
第一个表中tid唯一,第二个表tid不唯一
现在想以fid取出tid唯一的information,即只取重复中的一个记录
...全文
86 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
-狙击手- 2008-07-29
  • 打赏
  • 举报
回复
select a.tid,a.fid ,b.information
from tb1 a
left join (select tid,max(information) as information from tb2 group by tid) b
on a.tid = b.tid
hery2002 2008-07-29
  • 打赏
  • 举报
回复
聚合一下就可以了
select a.fid,min(b.informaiton) as information from a 
inner join b on a.tid = b.id
group by a.fid
bamboo_jaing 2008-07-29
  • 打赏
  • 举报
回复
select a.tid,b.tid from fid a inner join information b on a.id=b.id 或者
select a.tid,b.tid from fid a left join information b on a.id=b.id
pt1314917 2008-07-29
  • 打赏
  • 举报
回复


select a.*,b.* from 第一个表 a,第二个表 b
where a.tid=b.tid
and not exists(select 1 from 第二个表 where tid=b.tid and information>b.information )

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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