土豆大布丁 2021-09-07 14:29 采纳率: 57.1%
浏览 163
已结题

sqlite查询多个表中字段相同的数据

一共有6个表
其中两两为一组
如一组中一个表字段为memberid,name,idcard另一个表记录memberid,money,conut.
现在要在三组内找到姓名相同的记录怎么处理

img

  • 写回答

5条回答 默认 最新

  • 全栈极简 博客专家认证 2021-09-07 20:59
    关注

    如下sql已在sqlite中测试通过。

    
    --创建临时表,保存数据
    create temporary table tempFilterTable(MemberID,name,idcard,money,count)
    
    --将数据插入到临时表,注意是union all,这样重复的数据一样会保存
    insert into tempFilterTable(MemberID,name,idcard,money,count) 
    select MemberID,name,idcard,money,count from (
    select t1.[MemberID],t1.[name],t1.[idcard],ext1.[money],ext1.[count] from t1 left join ext1 on t1.[MemBerID] = ext1.[MemBerID]
    union all
    select t2.[MemberID],t2.[name],t2.[idcard],ext2.[money],ext2.[count] from t2 left join ext2 on t2.[MemBerID] = ext2.[MemBerID]
    union all
    select t3.[MemberID],t3.[name],t3.[idcard],ext3.[money],ext3.[count] from t3 left join ext3 on t3.[MemBerID] = ext3.[MemBerID]) t
    
    --筛选出姓名重复出现1次以上的数据
    select * from tempFilterTable where name in (SELECT [name] FROM tempFilterTable GROUP BY [name] HAVING count(*) > 1 ) order by name
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 9月15日
  • 已采纳回答 9月7日
  • 修改了问题 9月7日
  • 创建了问题 9月7日

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来