数据库题
person(id,name,sex)
relation(id1,id2,relation)
relation为0,关系为夫妻,id1是丈夫,id2是妻子
列出所有男人的姓名和他妻子的姓名,没妻子的妻子姓名为null
sql语句
以前从没有在检索字段里嵌套过查询语句:
select
husband.name,
(select name from person where id=relation.id2) as wifeName
from person husband, relation
where
husband.id=relation.id1(+)
husband.sex='F'
and relation=0
person(id,name,sex)
relation(id1,id2,relation)
relation为0,关系为夫妻,id1是丈夫,id2是妻子
列出所有男人的姓名和他妻子的姓名,没妻子的妻子姓名为null
sql语句
以前从没有在检索字段里嵌套过查询语句:
select
husband.name,
(select name from person where id=relation.id2) as wifeName
from person husband, relation
where
husband.id=relation.id1(+)
husband.sex='F'
and relation=0