表A
id  sex Name .......
1   1    a 
2   2    b
3   1    c
4   2    d
表B
id  Aid  score ........
1   1     123
2   3     234 
3   2     345
4   4     456期望结果
sex1Name score1  sex2Name score2
  a       123      b        345
  c       234      d        456多谢个为大侠

解决方案 »

  1.   

    应该可以用case when then 实现,现在有事,先给思路,到晚上没解决,再帮你看一下
    思路可参考:
    http://topic.csdn.net/t/20050923/08/4288492.html
    mysql的sql也可以用case when then的
      

  2.   

      a 123 b 345
      c 234 d 456
    这个咚咚 为啥要折行?
      

  3.   

    经测试OK:
    测试用SQL:create table test1 (id integer,sex integer,Name varchar(10));
    insert into test1 values(1, 1, 'a');  
    insert into test1 values(2, 2, 'b');
    insert into test1 values(3, 1, 'c');
    insert into test1 values(4, 2, 'd');
    create table test2(id integer, Aid  integer,score integer);
    insert into test2 values(1,1,123);
    insert into test2 values(2,3,234);
    insert into test2 values(3,2,345);
    insert into test2 values(4,4,456);查询SQLselect c.name as sex1Name,c.score as score1, d.name as sex2Name,d.score as score2  from
    (select a.id, a.name,b.score
       from test1 a,test2 b where a.id=b.id and a.id%2=1) c,
    (select a.id, a.name,b.score
       from test1 a,test2 b where a.id=b.id and a.id%2=0) d 
     where c.id=d.id-1;结果:
    +----------+--------+----------+--------+
    | sex1Name | score1 | sex2Name | score2 |
    +----------+--------+----------+--------+
    | a        |    123 | b        |    234 |
    | c        |    345 | d        |    456 |
    +----------+--------+----------+--------+
    2 rows in set (0.00 sec)
      

  4.   

    发错板块了 不打算结了
    同样问题在mysql板块发布已经揭贴