两张表分别是表A: id, companyName,value 其中id是主键 companyName是String类型
              B:   id,companyName,weight 其中id是主键,weight 是INT型,companyName有可能重复,但每个ID对应一个不重复的weight  ,现在要求查出A中所有记录并按照companyName的weight大小进行排序!

解决方案 »

  1.   

    两张表分别是表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 
      

  2.   

    select id, a.companyName,a.value
    from a left join b
    using(id)
    order by b.weight
      

  3.   

    select A.id,A.companyName,B.weight 
    from A left join B
    on A.id = B.id 
    order by B.weight ; ---默认是升序
      

  4.   

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

  5.   


    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