From 1b69fa57f2c0da5c971aa0a335c401cd9c7b9e26 Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Sun, 11 Oct 2026 09:43:56 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=8A=96=E9=9F=B3=E6=AF=8F=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E6=9C=80=E8=BF=91=E4=B8=80=E6=9D=A1=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E7=9A=84=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在真库上跑通过(42 个账号)。5.7 没有窗口函数,所以「每个博主最新那条」用相关子 查询挑;账号清单取「作品里出现过的 ∪ 有账号资料的」,否则那些没有作品的号会整行 消失。查询文件里写了这两条的原因,免得下次有人顺手改成 ROW_NUMBER()。 --- .gitignore | 1 + docs/queries/douyin-latest-video.sql | 85 ++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 docs/queries/douyin-latest-video.sql diff --git a/.gitignore b/.gitignore index 5278127..147cc33 100644 --- a/.gitignore +++ b/.gitignore @@ -199,3 +199,4 @@ webui/.npm/ .vnc_check.py .vnc_probe.py .vncshot.png +.q.sql diff --git a/docs/queries/douyin-latest-video.sql b/docs/queries/douyin-latest-video.sql new file mode 100644 index 0000000..a37f441 --- /dev/null +++ b/docs/queries/douyin-latest-video.sql @@ -0,0 +1,85 @@ +-- 抖音所有账号,各自最近一条视频 + 标签 + 详细数据 +-- +-- 直接在 MySQL 5.7 里跑(生产库 mediacrawler_prod)。已实测:42 个账号,包含 +-- **一条作品都没有的**(那些行的作品列是空的)—— 它们出现在列表里是有意的, +-- 和界面上的作品栏一致。 +-- +-- 为什么写成这个形状: +-- +-- * **5.7 没有窗口函数**,ROW_NUMBER() 用不了。所以「每个博主最新那条」是用 +-- 相关子查询 `ORDER BY published_at DESC LIMIT 1` 挑的,而不是 rank 之后取 1。 +-- * 账号清单取的是 **作品里出现过的 ∪ 有账号资料的**(`UNION` 去重)。只从作品里取 +-- 的话,那些「加了目标、也采到了粉丝数、但一条作品都没有」的号会整行消失。 +-- * 「最新」按 **published_at**(作者发布时间)排,不是 last_seen_at。降级路径 +-- (作品列表被风控挡住)会把所有已知作品都刷一遍,那时 last_seen_at 全都一样, +-- 按它排等于没排。 +-- * 指标取**最近一轮**(run_id 最大)的快照。注意抖音作品目前没有 published_at +-- 为空的,所以不存在「没有日期的作品排哪儿」的问题。 +-- +-- 只想看某一个任务的话,把四处 `t.platform = 'dy'` 换成对应的 task_id,例如: +-- WHERE t1.id = 7 +-- (四处指的是:账号清单里两处、最新作品子查询一处、账号快照子查询一处。) + +SELECT + acct.creator_hash AS 博主哈希, + ca.alias AS 博主备注, + COALESCE(n.creator_name, st.nickname, '') AS 博主昵称, + st.fans AS 粉丝数, + st.total_favorited AS 总获赞, + st.works_count AS 主页作品数, + n.note_id AS 作品ID, + n.title AS 作品标题, + n.note_url AS 作品链接, + FROM_UNIXTIME(n.published_at / 1000) AS 发布时间, + m.liked_count AS 点赞, + m.comment_count AS 评论, + m.collected_count AS 收藏, + m.share_count AS 分享, + (SELECT GROUP_CONCAT(t.name ORDER BY t.sort_order SEPARATOR ' / ') + FROM monitor_note_tag nt + JOIN monitor_tag t ON t.id = nt.tag_id + WHERE nt.platform = 'dy' AND nt.note_id = n.note_id) AS 标签, + (SELECT na.alias FROM monitor_note_alias na + WHERE na.platform = 'dy' AND na.note_id = n.note_id LIMIT 1) AS 作品备注 +FROM ( + -- 账号清单:作品里出现过的 + SELECT n1.creator_hash + FROM monitor_note n1 + JOIN monitor_task t1 ON t1.id = n1.task_id + WHERE t1.platform = 'dy' + UNION + -- ∪ 有账号资料的(包含一条作品都没有的博主) + SELECT s1.creator_hash + FROM monitor_creator_stat s1 + JOIN monitor_task t2 ON t2.id = s1.task_id + WHERE t2.platform = 'dy' +) acct +-- 这个博主最新的一条作品 +LEFT JOIN monitor_note n + ON n.id = (SELECT n2.id + FROM monitor_note n2 + JOIN monitor_task t3 ON t3.id = n2.task_id + WHERE t3.platform = 'dy' + AND n2.creator_hash = acct.creator_hash + ORDER BY n2.published_at DESC, n2.id DESC + LIMIT 1) +-- 那条作品最近一轮的指标 +LEFT JOIN monitor_note_metric m + ON m.id = (SELECT m2.id + FROM monitor_note_metric m2 + WHERE m2.task_id = n.task_id + AND m2.note_id = n.note_id + ORDER BY m2.run_id DESC + LIMIT 1) +LEFT JOIN monitor_creator_alias ca + ON ca.platform = 'dy' AND ca.creator_hash = acct.creator_hash +-- 博主最近一轮的账号级指标 +LEFT JOIN monitor_creator_stat st + ON st.id = (SELECT s2.id + FROM monitor_creator_stat s2 + JOIN monitor_task t4 ON t4.id = s2.task_id + WHERE t4.platform = 'dy' + AND s2.creator_hash = acct.creator_hash + ORDER BY s2.run_id DESC + LIMIT 1) +ORDER BY st.fans DESC, acct.creator_hash