android里面怎么在一张表中查询出2条字段数据交叉

逍遥笑 2014-06-06 11:42:31
例如A条记录的id为1,otherID为2
B记录的id为2,otherID为1,
怎么同时将这2条记录查询出来,就这2个字段的数据的关联的
...全文
153 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
逍遥笑 2014-06-06
  • 打赏
  • 举报
回复
引用 6 楼 hjywyj 的回复:
[quote=引用 5 楼 rtyou1234 的回复:] 这个groups提示没这一行
我这没问题啊。 还有个思路: select * from tb t1 where t1.id<t1.otherID and exists(select 1 from tb t2 where t1.id=t2.otherID and t1.otherID=t2.id) 查出来的都是id<otherid的那一条,然后java代码中循环遍历的时候add两条就可以 add(id,otherid) add(otherid,id)[/quote] 恩,好的,谢谢了哈
  • 打赏
  • 举报
回复
引用 5 楼 rtyou1234 的回复:
这个groups提示没这一行
我这没问题啊。 还有个思路: select * from tb t1 where t1.id<t1.otherID and exists(select 1 from tb t2 where t1.id=t2.otherID and t1.otherID=t2.id) 查出来的都是id<otherid的那一条,然后java代码中循环遍历的时候add两条就可以 add(id,otherid) add(otherid,id)
逍遥笑 2014-06-06
  • 打赏
  • 举报
回复
引用 4 楼 hjywyj 的回复:
[quote=引用 3 楼 rtyou1234 的回复:] 这个怎么分组的?2条关联的记录在一起
那就再嵌套一层 select id,otherID from(select *,groups=(case when t1.id<t1.otherID then rtrim(t1.id)+','+rtrim(t1.otherID) else rtrim(t1.otherID)+','+rtrim(t1.id) end) from tb t1 where exists(select 1 from tb t2 where t1.id=t2.otherID and t1.otherID=t2.id) )t order by groups[/quote] 这个groups提示没这一行
  • 打赏
  • 举报
回复
引用 3 楼 rtyou1234 的回复:
这个怎么分组的?2条关联的记录在一起
那就再嵌套一层 select id,otherID from(select *,groups=(case when t1.id<t1.otherID then rtrim(t1.id)+','+rtrim(t1.otherID) else rtrim(t1.otherID)+','+rtrim(t1.id) end) from tb t1 where exists(select 1 from tb t2 where t1.id=t2.otherID and t1.otherID=t2.id) )t order by groups
逍遥笑 2014-06-06
  • 打赏
  • 举报
回复
引用 2 楼 hjywyj 的回复:
select * from tb t1 where exists(select 1 from tb t2 where t1.id=t2.otherID and t1.otherID=t2.id)
这个怎么分组的?2条关联的记录在一起
  • 打赏
  • 举报
回复
select * from tb t1 where exists(select 1 from tb t2 where t1.id=t2.otherID and t1.otherID=t2.id)
十三邵 2014-06-06
  • 打赏
  • 举报
回复
例如A条记录的id为1,otherID为2 B记录的id为2,otherID为1, 怎么同时将这2条记录查询出来,就这2个字段的数据的关联的 我也不会,帮你顶一下吧。。。

80,330

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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