当前位置: 代码迷 >> Oracle技术 >> 如何实现数据库里面数据关联
  详细解决方案

如何实现数据库里面数据关联

热度:100   发布时间:2016-04-24 08:30:44.0
怎么实现数据库里面数据关联?
数据库里有4个字段,分别是:名字,年龄,性格,IP地址。
名字不为空,其它有为空的情况。比如名字给出一个:张三
那是可以把名字是:张三 的记录都找出来

张三 ,18,开朗,127.0.0.1
张三 ,22,开朗,13.0.1.2 

我要的效果是所有有关联的数据都要查出来。
这就是
名字是张三的
年龄是18 or 22
性格是开朗
ip是127.0.0.0 or 13.0.1.2

------解决方案--------------------
这样么? 如果要查询一个人 where 就可以了
 
SQL code
select col1 姓名,       replace(wm_concat(col2),',',' or ') 年龄,       replace(wm_concat(col3),',',' or ') 性格,       replace(wm_concat(col4),',',' or ') ip地址from t1group by col1    姓名     年龄        性格              ip地址---------------------------------1   李四   21 or 21   成熟 or 成熟   127.0.0.3 or 13.0.1.32   王五   25         大器           127.0.0.83   张三   18 or 18   开朗 or 开朗   127.0.0.1 or 13.0.1.2
------解决方案--------------------
SQL code
select * from table where age in(select distinct age from table where name='张三')union all select * from table where xingge in(select distinct xingge from table where name='张三')union all select * from table where ip in(select distinct ip from table where name='张三')
  相关解决方案