我有两个表table1,table2table1有字段a,b
a    b
小明  20
小华  30
小方  40
table2 有字段 c,d
c     d
小明   5000
小利   2000
小光   1000
小方   4000
小华   3000我要查询出这样的结果小明 20 5000
小华 30 3000
小方 40 4000
怎么查询呢?在线等,马上给分

解决方案 »

  1.   

    select a.a,a.b,b.d from table1 a join table2 b on a.a=b.c
      

  2.   

    select t1.* , t2.d from t1 , t2 where t1.a = t2.c
      

  3.   

    select t1.a , t1.b,t2.d from table1  t1
    left join (select c,sum(d) as d from table 2 group by c ) t2
    on t1.a= t2.c
      

  4.   

    create table t1(a varchar(10) ,   b int)
    insert into t1 values('小明' , 20 )
    insert into t1 values('小华' , 30 )
    insert into t1 values('小方' , 40 )
    create table t2(c varchar(10) ,   d int)
    insert into t2 values('小明' , 5000 )
    insert into t2 values('小利' , 2000 )
    insert into t2 values('小光' , 1000 )
    insert into t2 values('小方' , 4000 )
    insert into t2 values('小华' , 3000 )goselect t1.* , t2.d from t1 , t2 where t1.a = t2.c
    drop table t1, t2
    /*
    a          b           d           
    ---------- ----------- ----------- 
    小明         20          5000
    小方         40          4000
    小华         30          3000(所影响的行数为 3 行)*/
      

  5.   

     select table1.a,table1.b,table2.d where table1.a=table2.c
      

  6.   

    select t1.a , t1.b,t2.d from (select a , sum(b) as b from table1 group by a ) t1
    inner join (select c,sum(d) as d from table 2 group by c ) t2 on t1.a= t2.c
      

  7.   

    select table1.a,table1.b,table2.d from table1 where table1.a=table2.c
      

  8.   

    select A.a,A.b,B.d form table1 A,table2 B where A.a=B.c
      

  9.   

    select a.a,a.b,b.d from table1 a join table2 b on a.a=b.c