有时查询字段显示内容较多,浏览拖动滚动条觉得不方便,需要限制列宽。找到一个变通方法,通过限制内容长度来自定义列宽,以反链查询(链接 ID 20220311093846-z7l5g46
)为例:
1、不限制列宽的代码示例:
SELECT
'[' || a.content || '](siyuan://blocks/' || a.id || ')' AS __3____pre__链接内容,
'[' || b.content || '](siyuan://blocks/' || b.id || ')' AS __2____pre__上级内容,
'[' || c.content || '](siyuan://blocks/' || c.id || ')' AS __1____pre__文档
FROM
blocks As a
INNER JOIN blocks AS b ON a.parent_id = b.id
INNER JOIN blocks AS c ON a.root_id = c.id
WHERE
(
(a.type = 'p' OR a.type = 'h') AND a.markdown LIKE '%20220311093846-z7l5g46%'
)
ORDER BY
a.hpath
2、限制列宽的代码示例:
SELECT
'[' || (CASE
WHEN length(a.content)>16 then substr(a.content,1,16)
ELSE a.content
END
) || '](siyuan://blocks/' || a.id || ')' AS __3____pre__链接内容,
'[' || (CASE
WHEN length(b.content)>16 then substr(b.content,1,16)
ELSE b.content
END
) || '](siyuan://blocks/' || b.id || ')' AS __2____pre__上级内容,
'[' || (CASE
WHEN length(c.content)>50 then substr(c.content,1,50)
ELSE c.content
END
) || '](siyuan://blocks/' || c.id || ')' AS __1____pre__文档
FROM
blocks As a
INNER JOIN blocks AS b ON a.parent_id = b.id
INNER JOIN blocks AS c ON a.root_id = c.id
WHERE
(
(a.type = 'p' OR a.type = 'h') AND a.markdown LIKE '%20220311093846-z7l5g46%'
)
ORDER BY
a.hpath
参考:
[1]SQLite 常用函数
[2]sqlite 截取字符串的函数使用实例
建议:思源能否让 Sql 函数象其他命令一样在代码块中高亮显示。
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于