急,求SQL!!!

zcwsinosoft 2011-05-08 06:27:00
两张表分别是表A: id, companyName,value 其中id是主键 companyName是String类型
B: id,companyName,weight 其中id是主键,weight 是INT型,companyName有可能重复,但每个ID对应一个不重复的weight ,现在要求查出A中所有记录并按照companyName的weight大小进行排序!
...全文
155 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
meng0912 2011-05-25
  • 打赏
  • 举报
回复
学习!学习!
不要悲剧人生 2011-05-25
  • 打赏
  • 举报
回复
楼上的不错。
304的的哥 2011-05-25
  • 打赏
  • 举报
回复

SQL> select * from ta;

ID COMPANY_NAME VALUE
----------- ---------------------------------------- ----------------
1001 microsoft 85000000000
1002 apple 70000000000
1003 google 75000000000
1004 lenovo 5000000000
1005 taobao 100000000000

SQL> select * from tb;

ID COMPANY_NAME NUM_OF_EMP
------------ ---------------------------------------- -----------
1005 taobo 5000
1003 google 20000
1004 lenovo 5600
1002 apple 8000
SQL> select ta.id,ta.company_name,ta.value,tb.num_of_emp
2 from ta,tb
3 where ta.company_name=tb.company_name(+)
4 order by tb.num_of_emp
5 /

ID COMPANY_NAME VALUE NUM_OF_EMP
----------- ---------------------------------------- ---------------- -----------
1004 lenovo 5000000000 5600
1002 apple 70000000000 8000
1003 google 75000000000 20000
1001 microsoft 85000000000
1005 taobao 100000000000
sevenhc 2011-05-25
  • 打赏
  • 举报
回复
顶。。。
yejihui9527 2011-05-25
  • 打赏
  • 举报
回复
select a.* from a,b where a.id = b.id(+) order by b.weight
q270634296 2011-05-23
  • 打赏
  • 举报
回复
顶,楼上的都正确
kakaxi 2011-05-16
  • 打赏
  • 举报
回复
顶!楼上们的都是正解。
asggadfgadfg 2011-05-15
  • 打赏
  • 举报
回复
不用回答了,楼上的都是正解
fendou1314 2011-05-15
  • 打赏
  • 举报
回复
select A.id,A.companyName,B.weight
from A left join B
on A.id = B.id
order by B.weight ; ---默认是升序
asggadfgadfg 2011-05-08
  • 打赏
  • 举报
回复
select id, a.companyName,a.value
from a left join b
using(id)
order by b.weight
秋雨飘落 2011-05-08
  • 打赏
  • 举报
回复
两张表分别是表A: id, companyName,value 其中id是主键 companyName是String类型
B: id,companyName,weight 其中id是主键,weight 是INT型,companyName有可能重复,但每个ID对应一个不重复的weight ,现在要求查出A中所有记录并按照companyName的weight大小进行排序!


select a.* from a,b where a.id = b.id(+) order by b.weight

3,494

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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