1 数量过滤类

子块数量小于2的文档块(可能是空块)

  1. select *
  2. from blocks
  3. where id in (
  4. select root_id
  5. from blocks
  6. group by root_id
  7. having count(root_id )<=2
  8. )

被引用数量超过6的块(超级节点)

  1. select *
  2. from blocks
  3. where id in (
  4. select def_block_id
  5. from refs
  6. group by def_block_id
  7. having count(def_block_id )>=6
  8. )

引用其他文档数量超过6次的块(可能是moc)

  1. select *
  2. from blocks
  3. where id in (
  4. select block_id
  5. from refs
  6. group by block_id
  7. having count(block_id )>=6
  8. )

完全没有被引用的文档

  1. select *
  2. from blocks
  3. where not id in (
  4. select root_id
  5. from refs
  6. )
  7. and type ='d'

2 时间类

一个月以上没有更新的文档(可能是死文档或者应当归档的文档)

  1. select *
  2. from blocks
  3. where updated < strftime('%Y%m%d%H%M%S',datetime('now','-1 month'))
  4. and type ='d'
  5. or type ='doc'

3 特殊排序

按照内容模式排序

这里举个例子
假设有四个同事的简介文档
image.png
image.png
image.png
image.png
现在需要在一个地方文档里汇总这些同事的联系方式那些,但是想要去掉生日

  1. select *
  2. from blocks
  3. where type = "h"
  4. and root_id in (
  5. select id
  6. from blocks
  7. where content like "%同事%"
  8. )
  9. and content not like "%生日%"
  10. order by
  11. root_id, (
  12. case
  13. when content = "姓名" then 0
  14. when content = "电话" then 1
  15. when content = "住址" then 2
  16. end
  17. )

结果是这样的
image.png