mysql 查询问题急 四小时之内结帖

qq369759459 2010-05-06 04:03:31
表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

多谢个为大侠





...全文
128 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sean_ping 2010-07-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 keiy 的回复:]

经测试OK:
测试用SQL:
SQL code

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……
[/Quote]

风之谷 2010-07-20
  • 打赏
  • 举报
回复
4个月了
xinxiangsui2008 2010-07-20
  • 打赏
  • 举报
回复
我就来看看什么时候结帖!!
ilovemovieboy 2010-07-16
  • 打赏
  • 举报
回复
四小时内结帖?骗子!
tjg5202 2010-07-13
  • 打赏
  • 举报
回复
看帖回帖
kye_jufei 2010-07-08
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 keiy 的回复:]
经测试OK:
测试用SQL:

SQL code

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, ……
[/Quote]
支持
qq369759459 2010-05-07
  • 打赏
  • 举报
回复
不过感谢大家 分是要给的 今天晚上再结
qq369759459 2010-05-07
  • 打赏
  • 举报
回复
发错板块了 不打算结了
同样问题在mysql板块发布已经揭贴
风之谷 2010-05-07
  • 打赏
  • 举报
回复
占个茅坑
yanele 2010-05-07
  • 打赏
  • 举报
回复
我是来看楼主是否兑现的。
varick_zhong 2010-05-07
  • 打赏
  • 举报
回复
我是来接分的
Q724481678Q 2010-05-06
  • 打赏
  • 举报
回复
4小时已经过去,楼主请结账
柯本 2010-05-06
  • 打赏
  • 举报
回复
经测试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);

查询SQL

select 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)
okgxs 2010-05-06
  • 打赏
  • 举报
回复
a 123 b 345
c 234 d 456
这个咚咚 为啥要折行?
柯本 2010-05-06
  • 打赏
  • 举报
回复
应该可以用case when then 实现,现在有事,先给思路,到晚上没解决,再帮你看一下
思路可参考:
http://topic.csdn.net/t/20050923/08/4288492.html
mysql的sql也可以用case when then的
qq369759459 2010-05-06
  • 打赏
  • 举报
回复
发错地方了 不好意思

2,507

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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