SQLite动态层次结构

时间:2019-01-02 05:25:03

标签: sqlite

帮助我如何在下面的输出中编写此查询。找到我的表格数据

id                    cat                    sub-cat          sub-sub
1                      remarkable   
2                      bsorpti_upd  
3                      ntimicrobiasdfsdf
4                      remarkable                Dissolve
5                      macokinetics
6                      pharmacodynamics 
7                      pharmacodynamics          Antimicrobial 
8                      pharmacodynamics          Antimicrobial          peptite
9                      Test 
10                     ideas    
11                     Test                      biologically

我希望输出为

column

Remarkable
         Dissolve 
bsorpti_upd
ntimicrobiasdfsdf
macokinetics
pharmacodynamics
        Antimicrobial
               peptite
Test
         biologically
ideas               

1 个答案:

答案 0 :(得分:0)

SELECT printf('%* s', 案件 当nullif(sub-cat,'')为NULL时 然后4 当NULLIF(sub-sub,'')为NULL时 然后8 其他12 结束, ' ' )|| COALESCE(NULLIF(sub-sub,''),NULLIF(sub-cat,''),cat)作为列 FROM索引表t ORDER BY Primaryterm, 案件 当NULLIF(sub-cat,'')为NULL时 然后4 当NULLIF(sub-sub,'')为NULL时 然后8 其他12 结束, COALESCE(NULLIF(sub-sub,''),NULLIF(sub-cat,''),cat)