25d895d 🐛 fix(gitea_workflow): clean up temp repos after job steps 2bc3b11 🐛 fix(gitea_workflow): clean up temporary repo dirs in workflows 98c3f30 📝 docs(agent_rules): allow plan execution on current branch 16c7230 📝 docs(prompts): define custom verify layering 8efc4dd 🐛 fix(skills): quote commit-message description bc8498f 🐛 fix(ci): install tomli for gitea tests 55cda3b 🐛 fix(tests): report missing toml parser clearly c0729c7 🐛 fix(playbook): import Optional for cli compatibility 63e24bf 📦 deps(skills): sync thirdparty skills d2f9356 🐛 fix(ci): isolate gitea workflow repos 588b81d 🐛 fix(ci): inline gitea workflow bootstrap e0b1c3a ♻️ refactor(skills): standardize first-party skill contracts 2c5050d ♻️ refactor(skills): rename repo skills source dir f049dfb 📦 deps(skills): drop duplicate first-party superpowers skills 234b335 ✨ feat(workflow): add superpowers planning and execution state tracking c1702a6 📝 docs(markdown): format tracked markdown and drop stale templates 2325409 📝 docs(markdown): clarify optional markdownlint usage 214c44e 🔧 chore(markdown): add markdownlint baseline and lint fixes a22b324 📝 docs(templates): add execution and memory-bank prompt templates 223a797 📝 docs(templates): update README for Claude Code and current features 4ac8672 📝 docs: simplify README + platform-agnostic tools + auto-create local rules 2431c9d 📝 docs: add claude_md config and use cross-platform paths d64b248 📝 docs: fix README.md inaccuracies and add Claude Code info c8d6bf2 🐛 fix(playbook): use relative paths in CLAUDE.md when not at project root 6518f0f ✨ feat(playbook): auto-create CLAUDE.md with path discovery 6ec9a45 ✨ feat(skills): add skill_link symlink support + platform-agnostic prompt 9f8b6b5 📝 docs: update README and config example for Claude Code support 79cff6c 📝 docs(skills): add Claude Code platform support 452c6f5 ✨ feat(playbook): auto-inject AGENTS.md into CLAUDE.md e1dbf3c 🐛 fix(skills): remove dual-path from commit-message skill f3a7259 🔧 chore(ci): use prepare_repo.sh in both workflows da08212 🔧 chore(ci): extract prepare_repo.sh and clean up workflows 7ade85e 🗑️ remove(tsl): drop syntax_book/, data/ source and build script f94dba0 ♻️ refactor(skills): update playbook.py and tests for thirdparty/ layout b3df412 ♻️ refactor(skills): separate thirdparty skills into thirdparty/ subdirectory 64950e7 📦 deps(skills): sync thirdparty skills a2e3cb0 ✨ feat(playbook): add no_backup deploy controls 8609d59 🐛 fix(docs): repair reference catalog source links 956da11 🐛 fix(playbook): publish hidden ci test fixes 3f67754 📦 deps(skills): sync thirdparty skills 08ca87b 📦 deps(skills): add karpathy thirdparty sync 96b705b 📝 docs(tsl): rebuild canonical syntax and routing manual 3ed5052 📦 deps(skills): sync thirdparty skills 60108dd 📦 deps(skills): sync thirdparty skills da85d4e 🐛 fix(thirdparty): prune nested project snapshots a2a697e 📦 deps(skills): sync thirdparty skills 9df610a 🐛 fix(thirdparty): exclude duplicated superpowers skills 33dd5bb 🐛 fix(thirdparty): preserve optional manifest fields 91b0ea7 🐛 fix(thirdparty): preserve manifest during snapshot update 2e26f98 🔧 chore(thirdparty): generalize skills sync pipeline 5b9c1e3 📦 deps(skills): sync superpowers 2f2d34a 📝 docs(readme): normalize subtree command spacing 62db7db 🐛 fix(ci): serialize superpowers update and sync 3463223 🐛 fix(ci): use literal superpowers sync paths 48f6de8 📦 deps(skills): sync superpowers 4b23529 🔧 chore(ci): merge superpowers update and sync workflow a56d75b 📦 deps(skills): sync superpowers 84bcefa 🔧 chore(ci): use ci[bot] commit author name 00a07e5 📦 deps(skills): sync superpowers 7b84daf 🐛 fix(templates): enforce main loop progress tracking 51373d7 🔧 chore(ci): automate superpowers sync workflow eaaa39c 🐛 fix(ci): prevent stale superpowers sync from restoring skills block 79755c6 📦 deps(skills): sync superpowers 836d878 📦 deps(skills): sync superpowers 8216c9f 📦 deps(skills): sync superpowers 9439505 🐛 fix(playbook): address reported repo issues git-subtree-dir: docs/standards/playbook git-subtree-split: 25d895d8b3f56624ccfe99ad7289e9eb49e0f316
5.5 KiB
TS-SQL Advanced
文档类型:语法主线 是否可直接用于生成代码:是 是否含已验证可执行示例:是 是否含已验证反例:是 遇到不确定时跳转到:28_ts_sql_core.md、15_ts_sql.md、12_pitfalls.md
手册位置:第 29 篇,共 32 篇。上一篇:28_ts_sql_core.md。下一篇:30_runtime_services_and_global_cache.md。
这一篇只收当前已经实测通过的 TS-SQL 进阶查询能力:多表 join、分组子查询 ThisGroup、排序后的原始行下标 ThisRowIndex,以及 RefMaxOf / RefMinOf 这类“取极值所在行的另一列”的写法。
这一篇解决什么问题
回答“基础 select 已经会写以后,怎样继续处理多表联接、分组后组内再查、以及极值对应行的引用值”。
必须记住的规则
- 多表
join时,字段访问应写成[表序号].["字段名"]。 ThisGroup不是普通值,而是分组后的子结果集;要通过子select/vselect的from ThisGroup来访问。ThisRowIndex在order by之后仍可返回原始行位置,而不是排序后的序号。RefMaxOf(...)和RefMinOf(...)在当前最小例子里可与MaxOf(...)/MinOf(...)配合,取极值所在行的另一列值。- 这一篇当前只提升“高级查询”部分;对象化写回接口和更深的时间序列查询仍然暂缓。
已验证语法
join
最小内存表联接:
代码块身份:已验证可执行示例
program test;
begin
A := array(
("ID": 1, "V1": 10),
("ID": 2, "V1": 20)
);
B := array(
("ID": 1, "V2": 100),
("ID": 3, "V2": 300)
);
R := select [1].["ID"], [1].["V1"], [2].["V2"]
from A join B on [1].["ID"] = [2].["ID"]
end;
end.
已验证运行结果:
R的长度是1- 唯一一行是
(1,10,100) - 说明当前解释器接受
from A join B on ...,并接受[1].["字段"]、[2].["字段"]这种多表字段访问
ThisGroup
分组后可在组内继续做子查询:
代码块身份:已验证可执行示例
program test;
begin
T := array(
("A": 1, "B": 3, "Name": "x"),
("A": 2, "B": 1, "Name": "y"),
("A": 1, "B": 2, "Name": "z")
);
G := select ["A"], maxb := maxof(["B"]) as "MaxB",
vselect ["Name"] from ThisGroup where ["B"] = maxb end as "TopName"
from T
group by ["A"]
order by ["A"]
end;
end.
已验证运行结果:
G的长度是2- 第一行是
(1,3,"x") - 第二行是
(2,1,"y") - 说明
ThisGroup可以在分组上下文里作为子结果集继续vselect
ThisRowIndex 在排序后仍指向原始位置
代码块身份:已验证可执行示例
program test;
begin
T := array(
("A": 1, "B": 3),
("A": 2, "B": 1),
("A": 1, "B": 2)
);
R := select ThisRowIndex as "Idx", ["B"]
from T
order by ["B"]
end;
end.
已验证运行结果:
R的三行依次是(1,1)、(2,2)、(0,3)- 说明
order by ["B"]之后,ThisRowIndex仍返回原表中的原始下标
RefMaxOf 与 RefMinOf
当前最小样例里,RefMaxOf / RefMinOf 可以和对应的极值聚集一起使用:
代码块身份:已验证可执行示例
program test;
begin
A := array((6, 20), (5, 20), (9, 2), (2, 20), (7, 18));
R1 := select maxof([0]) as "MaxA", refmaxof([1]) as "RefB" from A end;
R2 := select minof([0]) as "MinA", refminof([1]) as "RefB" from A end;
end.
已验证运行结果:
R1只有一行,结果是(9,2)R2只有一行,结果是(2,20)- 说明在这个最小例子里,
refmaxof([1])取到了[0]最大值所在行的[1],refminof([1])取到了[0]最小值所在行的[1]
暂不在本页展开的部分
with onleft join/right join/full joinRefsOfTSQLInsertTSQLSetValueTSQLBatchInsertTSQLEdit/TSQLPost/TSQLFinal- 更深的时间序列聚集与缓存选项
这些内容要等单独补最小验证后,再进入主线正文。
最小可编译示例
如果你只想先记住最短的高级查询骨架,从这个开始:
代码块身份:已验证可执行示例
R := select [1].["ID"], [2].["V2"]
from A join B on [1].["ID"] = [2].["ID"]
end;
常见误写
- 多表联接时继续写成
["ID"],没有加表序号。 - 把
ThisGroup当成普通字段或普通变量。 - 把排序后的
ThisRowIndex误当成排序序号。 - 在还没验证的情况下,把
with on、写回接口和时间序列缓存写进默认模板。
代码块身份:反例 / 不可照写
R := select ["ID"], ["V1"], ["V2"]
from A join B on ["ID"] = ["ID"]
end;
上面这种写法不要当成当前手册的可靠规则。多表查询里,当前只把 [1].["字段"]、[2].["字段"] 这种带表序号的访问方式提升为已验证主干。
代码块身份:反例 / 不可照写
Value := ThisGroup;
不要把 ThisGroup 当成普通值直接使用。当前可靠入口是 select ... from ThisGroup end 或 vselect ... from ThisGroup end。
跳转指引
- 回看 TS-SQL 基础:见 28_ts_sql_core.md
- 回看 TS-SQL 总入口:见 15_ts_sql.md
- 看运行时与全局缓存:见 30_runtime_services_and_global_cache.md