外观
cn_index_weight
1. 表用途与适用场景
- 用途:存储指数成分与权重快照。
- 常见场景:指数成分股追踪、权重分析、组合构建。
2. 主键 / ORDER BY / 引擎 / 分区
- 业务主键:
(index_code, date, stock_code) - ORDER BY:
(index_code, date, stock_code) - 引擎:
ReplacingMergeTree() - 分区:
toYYYYMM(date)
3. 字段说明
| 字段名 | 类型 | 含义 |
|---|---|---|
index_code | String | 指数代码 |
stock_code | String | 成分股代码 |
date | Date | 权重快照日期 |
weight | Nullable(Float64) | 权重 |
4. 示例 SQL
sql
-- 查看沪深300最新一期成分股权重
SELECT stock_code, weight
FROM market.cn_index_weight
WHERE index_code = '399300.SZ'
AND date = (SELECT max(date) FROM market.cn_index_weight WHERE index_code = '399300.SZ')
ORDER BY weight DESC
LIMIT 205. 对应 Python 示例
python
import seeddata as sd
sd.set_base_url("http://127.0.0.1:18637")
sd.set_token("your_token_here")
sql = """
SELECT index_code, date, count() AS cnt, sum(weight) AS total_weight
FROM market.cn_index_weight
WHERE date >= '2026-01-01'
GROUP BY index_code, date
ORDER BY date DESC, index_code
LIMIT 20
"""
print(sd.query(sql).df)6. 注意事项
date是权重快照日期,不是按交易日历展开的连续日频序列。- 查询建议显式带
date条件,避免跨分区全扫描。