晚街听风 2019-09-04 15:24 采纳率: 0%
浏览 844

同一个sql中显示同一个字段的3个值,以第一个结果作为第二个结果的条件,第二个结果作为第三个结果的条件

同一个sql中显示同一个字段的3个值,以第一个结果作为第二个结果的条件,第二个结果作为第三个结果的条件。怎么优化
例如:
select dictid from T where tid='1010104030403'; --10101040304
select dictid from T where tid='10101040304'; --101010403
select dictid from T where tid='101010403'; --1010104

select dictid level1,(select dictid from T where tid=(select dictid from T where tid='1010104030403')) level2,
(select dictid from T where tid=(select dictid from T where tid=(select dictid from T where tid='1010104030403'))) level3 from T where tid='1010104030403';

  • 写回答

3条回答

  • 听雨停了 2019-09-04 15:41
    关注

    这样就可以了。

    SELECT a.dictid,b.dictid,c.dictid FROM T AS a
    INNER JOIN T AS b ON a.dictid=b.tid
    INNER JOIN T AS c ON b.dictid=c.tid
    WHERE a.tid='1010104030403'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器