Dataview 使用指南
基础查询语法
1. 基本查询结构
TABLE|LIST|TASK
FROM "路径"
WHERE 条件
SORT 字段
GROUP BY 字段
LIMIT 数量
2. 查询类型
TABLE - 表格查询
table file.name as 文件名, file.mtime as 修改时间
from ""
sort file.mtime desc
LIST - 列表查询
list
from "3-Resources/AI System"
where contains(file.tags, "#核心")
TASK - 任务查询
task
from "1-Projects"
where !completed
高级用法
1. 文件属性查询
table file.name, file.size, file.ctime, file.mtime
from ""
where file.size > 1000
2. 链接关系查询
table file.name, length(file.inlinks) as 入链数, length(file.outlinks) as 出链数
from ""
sort length(file.inlinks) desc
3. 标签统计
table length(rows) as 数量
from ""
flatten file.tags as tag
group by tag
sort length(rows) desc
4. 文件夹统计
table length(rows) as 文件数量
from ""
group by file.folder
sort length(rows) desc
5. 日期范围查询
table file.name, file.mtime
from ""
where file.mtime >= date("2024-01-01")
sort file.mtime desc
6. 文本内容查询
list
from ""
where contains(file.content, "AI")
7. 任务统计
table file.name, length(file.tasks) as 总任务, length(file.tasks.where(t => t.completed)) as 已完成
from ""
where file.tasks
8. 自定义字段查询
table 作者, 状态, 优先级
from "1-Projects"
where 作者
实用查询模板
知识库概览
table file.name as 文件名, file.folder as 文件夹, file.tags as 标签
from ""
where file.name != "知识库索引"
sort file.mtime desc
limit 20
项目进度跟踪
table file.name as 项目名, length(file.tasks) as 总任务, length(file.tasks.where(t => t.completed)) as 已完成, round(length(file.tasks.where(t => t.completed)) / length(file.tasks) * 100, 1) + "%" as 完成率
from "1-Projects"
where file.tasks
sort 完成率 desc
学习资源统计
table length(rows) as 数量, round(length(rows) / length(rows) * 100, 1) + "%" as 占比
from "3-Resources"
group by file.folder
sort length(rows) desc
最近活跃内容
table file.name as 文件名, file.mtime as 修改时间, file.tags as 标签
from ""
where file.mtime >= date(today) - dur(7 days)
sort file.mtime desc
孤立文件(无入链)
list
from ""
where length(file.inlinks) = 0 and file.name != "知识库索引"
核心内容列表
list
from ""
where contains(file.tags, "#核心")
sort file.mtime desc
条件查询
文件类型过滤
list
from ""
where file.ext = "md"
标签组合查询
list
from ""
where contains(file.tags, "#AI") and contains(file.tags, "#核心")
日期条件
table file.name, file.mtime
from ""
where file.mtime >= date("2024-01-01") and file.mtime <= date("2024-12-31")
文件大小条件
table file.name, file.size
from ""
where file.size > 5000
sort file.size desc
聚合函数
统计函数
length() - 计算长度
sum() - 求和
average() - 平均值
min() - 最小值
max() - 最大值
round() - 四舍五入
示例
table length(file.tasks) as 任务数, sum(file.tasks.where(t => t.completed)) as 已完成
from "1-Projects"
实用技巧
1. 动态日期
date(today) - 今天
date(today) - dur(7 days) - 7天前
date(today) - dur(1 month) - 1个月前
2. 文本处理
contains(text, "关键词") - 包含关键词
startswith(text, "前缀") - 以某前缀开始
endswith(text, "后缀") - 以某后缀结束
3. 数组操作
flatten(array) - 扁平化数组
array.where(condition) - 过滤数组
array.sort() - 排序数组
4. 数学运算
+, -, *, / - 基本运算
round(number, decimals) - 四舍五入
标签
工具 Dataview 查询 知识管理 技术