请问一下这个inner join怎么写

kroda 2009-07-02 10:04:10
select emp.*,dept.* from emp,dept,
(
select rowid1,rowid2 from (select res.*, rownum rownum_
from (select emp.rowid rowid1,dept.rowid rowid2 from emp,dept where emp.deptno = dept.deptno) res
where rownum <= 6)
where rownum_ >= 4
) tt
where emp.rowid = tt.rowid1
and dept.rowid = tt.rowid2
and emp.deptno = dept.deptno

想改成inner join的方式 不知道怎么写
...全文
119 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
cqhweb 2009-07-02
  • 打赏
  • 举报
回复
看不懂究竟查出来是需要什么样的结果...看来楼主还不会发帖子

看不懂究竟查出来是需要什么样的结果...看来楼主还不会发帖子

看不懂究竟查出来是需要什么样的结果...看来楼主还不会发帖子
ChinaJiaBing 2009-07-02
  • 打赏
  • 举报
回复
select emp.*,dept.* from emp,dept,
(
select rowid1,rowid2 from (select res.*, rownum rownum_
from (select emp.rowid rowid1,dept.rowid rowid2 from emp,dept where emp.deptno = dept.deptno) res
where rownum <= 6)
where rownum_ >= 4
) tt
where emp.rowid = tt.rowid1
and dept.rowid = tt.rowid2
and emp.deptno = dept.deptno

想改成inner join的方式 不知道怎么写


select emp.*,dept.* from emp inner join
(
select rowid1,rowid2 from (select res.*, rownum rownum_ from
(select emp.rowid rowid1,dept.rowid rowid2 from emp,dept where emp.deptno = dept.deptno)
res
where rownum <= 6)
where rownum_ >= 4
) tt
on emp.rowid = tt.rowid1
inner join dept on dept.rowid = tt.rowid2
and emp.deptno = dept.deptno




dawugui 2009-07-02
  • 打赏
  • 举报
回复
select m.* from
(
select emp.rowid emp_rowid , emp.其他字段 , dept.rowid dept_rowid dept.其他字段 from emp inner join dept on emp.deptno = dept.deptno
) m
inner join
(
select rowid1,rowid2 from
(
select res.*, rownum rownum_ from (select emp.rowid rowid1,dept.rowid rowid2 from emp,dept where emp.deptno = dept.deptno
) res
where rownum <= 6
) n
on m.rowid = n.rowid1 and m.rowid = n.rowid2
where n.rownum_ >= 4
pt1314917 2009-07-02
  • 打赏
  • 举报
回复
select emp.*,dept.* from emp inner join dept on emp.deptno = dept.deptno  
inner join
(
select rowid1,rowid2 from (select res.*, rownum rownum_
from (select emp.rowid rowid1,dept.rowid rowid2 from emp,dept where emp.deptno = dept.deptno) res
where rownum <= 6)
where rownum_ >= 4
) tt on dept.rowid = tt.rowid2
and emp.rowid = tt.rowid1
izbox 2009-07-02
  • 打赏
  • 举报
回复

select emp.*,dept.* from emp inner join
(
select rowid1,rowid2 from (select res.*, rownum rownum_
from (select emp.rowid rowid1,dept.rowid rowid2 from emp,dept where emp.deptno = dept.deptno) res
where rownum <= 6)
where rownum_ >= 4
) tt on
emp.rowid = tt.rowid1 inner join
dept on emp.deptno = dept.deptno
JonasFeng 2009-07-02
  • 打赏
  • 举报
回复
语句贴完整,才可能写出来呀。
jiangshun 2009-07-02
  • 打赏
  • 举报
回复
select emp.*,dept.* from emp inner join dept on emp.deptno = dept.deptno where rownum <= 6 and rownum_ >= 4
等不到来世 2009-07-02
  • 打赏
  • 举报
回复
把语句贴完整先!
rownum_ 那一块……
soft_wsx 2009-07-02
  • 打赏
  • 举报
回复
网上的
inner join和where区别
1 WHERE子句中使用的连接语句,在数据库语言中,被称为隐性连接。INNER JOIN……ON子句产生的连接称为显性连接。(其他JOIN参数也是显性连接)WHERE和INNER JOIN产生的连接关系,没有本质区别,结果也一样。但是!隐性连接随着数据库语言的规范和发展,已经逐渐被淘汰,比较新的数据库语言基本上已经抛弃了隐性连接,全部采用显性连接了。   
2无论怎么连接,都可以用join子句,但是连接同一个表的时候,注意要定义别名,否则产生错误!   a> inner join:理解为“有效连接”,两张表中都有的数据才会显示left join:理解为“有左显示”,比如on a. ...
soft_wsx 2009-07-02
  • 打赏
  • 举报
回复
11楼真历害呀!
dawugui 2009-07-02
  • 打赏
  • 举报
回复
select m.* from
(
select emp.rowid emp_rowid , emp.其他字段 , dept.rowid dept_rowid ,dept.其他字段 from emp inner join dept on emp.deptno = dept.deptno
) m
inner join
(
select rowid1,rowid2 from
(
select res.*, rownum rownum_ from (select emp.rowid rowid1,dept.rowid rowid2 from emp,dept where emp.deptno = dept.deptno
) res
where rownum <= 6
) n
on m.emp_rowid = n.rowid1 and m.dept_rowid = n.rowid2
where n.rownum_ >= 4
kroda 2009-07-02
  • 打赏
  • 举报
回复
错了 是4楼 你为什么没在最外层写dept.rowid = tt.rowid2呢 这样会不会有问题
kroda 2009-07-02
  • 打赏
  • 举报
回复
4和5楼,你们为什么没有dept.rowid = tt.rowid2的关联呢

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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