问一个关于sql 查询 的问题

wuxing2006 2008-06-11 11:16:03
问一个关于sql 的问题
表 fair_comp
id name
1 test1
2 test2

表 comp_booth
id fair_comp_id name
1 1 booth1
2 1 booth2
3 1 booth3
4 2 booth4

当comp_booth里的记录条数大于2时,fair_comp显示为两条
希望结果为
select * from fair_comp .....
id name
1 test1
1 test1
2 test2

盼解
...全文
80 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
robin_ares 2008-06-11
  • 打赏
  • 举报
回复
Select a.* from
fair_comp a,
(select fair_comp_id ,
row_number() over (patition by fair_comp_id order by fair_comp_id ) row_number
from comp_booth
) b
where a.id = b.fair_comp_id
and b.row_number < 3
WangZWang 2008-06-11
  • 打赏
  • 举报
回复
Select a.* from fair_comp a,comp_booth b
where a.id=b.fair_comp_id and
(Select count(*) from comp_booth where id>b.id)<=2
wuxing2006 2008-06-11
  • 打赏
  • 举报
回复
这是一份迟来的爱 给分
doer_ljy 2008-06-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 Robin_Ares 的回复:]
Select a.* from
fair_comp a,
(select fair_comp_id ,
row_number() over (patition by fair_comp_id order by fair_comp_id ) row_number
from comp_booth
) b
where a.id = b.fair_comp_id
and b.row_number < 3
[/Quote]
支持

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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