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

同一个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'
    
    评论

报告相同问题?