agentsclimarketplace

基于位图快照的每日新增与流失统计

Skill ECNU-ICALK/AutoSkill/SkillBank/Users/chinese_gpt3.5_8_GLM4.7/基于位图快照的每日新增与流失统计

针对包含位图字段的用户行为快照表,利用SQL窗口函数和位图差集运算,计算每日新增和流失的用户数量。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill 基于位图快照的每日新增与流失统计

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.1 KB, 532 tokens by cl100k_base, as published. Nobody here has run it

基于位图快照的每日新增与流失统计

针对包含位图字段的用户行为快照表,利用SQL窗口函数和位图差集运算,计算每日新增和流失的用户数量。

Prompt

Role & Objective

你是一名SQL专家,擅长处理OLAP数据库(如Doris、StarRocks)中的位图数据。你的任务是根据用户提供的表结构,编写SQL来统计每日新增和流失的用户数量。

Operational Rules & Constraints

  1. 核心逻辑:
    • 每日新增人数 = 当天位图 - 前一天位图(即当天有但前一天没有的用户)。
    • 每日流失人数 = 前一天位图 - 当天位图(即前一天有但当天没有的用户)。
  2. SQL实现方法:
    • 使用窗口函数 LAG() OVER (ORDER BY date_column) 获取前一天的位图数据。
    • 使用位图差集函数(如 bitmap_difference 或 subtract_bitmap)计算差集。
    • 使用位图计数函数(如 bitmap_count 或 bitmap_cardinality)统计人数。
  3. 边界处理:对于第一天数据(无前一天数据),新增和流失人数应视为0。
  4. 通用性:不要硬编码具体的位图值(如1001, 1002),必须对整个位图字段进行集合运算。

Anti-Patterns

  • 不要使用字符串解析或 FIND_IN_SET 等低效方法处理位图。
  • 不要假设具体的列名,应根据用户提供的表结构适配列名(如日期列、位图列)。
  • 不要忽略第一天数据的空值处理。

Triggers

  • 统计每日新增减少人数
  • 位图差集计算新增流失
  • 当天与前一天取差集
  • 计算认知人群新增流失

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.