现在有一个主表a, 两个子表b、c ,父表a一条记录,在子表b中有多条记录。
现在要在一行中,列出父表a一记录,子表b和c对应的多条记录。
有没有办法实现,一行多条记录?
可利用函数实现.
既然是主从表,那就应该有个字段关联。比如:序号
select a.*,b.*,c.* from a a,b b ,c c
where a.no = b.no and a.no = c.no;
select a.*,b.*,c.* from a inner join b on a.no=b.no
inner join c on a.no=c.no
不可能实现的
sql语句不行
可以吧,就象LGQDUCKY(飘)说的,先问你是要这样的结果吗?
select a.*,b.*,c.* from a a,b b ,c c
where a.主键 = b.引用a的主键 and a.主键 = c.引用a的主键;
不清楚楼主所表达意图是怎样,列个例子吧
一行多条记录?
有多少条?条数固定的话可以,用case或者if
明白了,不能实现
你这是个交叉表,可以实现的.
select a.no,a.name,a.id,
decode(b.remark,aaaaa,b.remark) aaaaa,
decode(b.remark,bbbbb,b.remark) bbbbb,
decode(c.thing,ccccc,b.thing) ccccc,
decode(c.thing,ddddd,b.thing) ddddd
from a,b,c
where a.no=b.a_no and a.no=c.a_no
好像用sql语句不行
前台处理
select a.no,a.name,a.id,
decode(b.a_no,a.no,b.remark) aaaaa,
decode(c.a_no,a.no,c.thing) ddddd
from a,b,c
where a.no=b.a_no and a.no=c.a_no
基本方法如下,能不能实现看数据:
select no,name,
max( decode( a_no, no, remark, null ) ) no_10,
max( decode( a_no, no, remark, null ) ) no_20,
.....
max( decode( a_no, no, thing, null ) ) no_30,
max( decode( a_no, no, thing, null ) ) no_40,
....
from a,b,c
where a.no=b.a_no(+) and a.no=c.a_no(+)
group by no,name