问答交流

c_normalize只适用于单表

由bqj5fwt4创建,最终由bqj5fwt4 被浏览 22 用户

SELECT
    sf.instrument,
    sf.date as date,
    sf.total_market_cap,

    -- 从技术指标表中选择的字段
    ta.ma_golden,
    ta.ma_long,
    ta.volume_golden,
    ta.volume_long,
    ta.three_red_soldiers,
    ta.hammer,
    ta.morning_star,
    ta.kdj_golden,
    ta.kdj_long,
    0.4 * c_normalize(sf.total_market_cap) + 0.6 * c_normalize(sf.dividend_yield_ratio, sf.date) + 1 * c_normalize(ta.kdj_k - ta.kdj_d, sf.date)  AS score,
    

FROM
    cn_stock_factors AS sf
JOIN
    cn_stock_factors_ta AS ta
ON
    sf.instrument = ta.instrument AND sf.date = ta.date
    
  • \
    Error: Binder Error: Ambiguous reference to column name "date" in function "c_normalize" (use: "ta.date" or "sf.date")
    

问题在于我这里有两张表,所以可能无法使用,如何解决?

标签

金融数据技术指标数据处理
评论
  • ```
  • import dai
  • dai.query("""
  • SELECT
  • sf.instrument,
  • sf.date as date,
  • sf.total_market_cap,
  • -- 从技术指标表中选择的字段
  • ta.ma_golden,
  • ta.ma_long,
  • ta.volume_golden,
  • ta.volume_long,
  • ta.three_red_soldiers,
  • ta.hammer,
  • ta.morning_star,
  • ta.kdj_golden,
  • ta.kdj_long,
  • 0.4 * c_normalize(sf.total_market_cap) + 0.6 * c_normalize(sf.dividend_yield_ratio) + 1 * c_normalize(ta.kdj_k - ta.kdj_d) AS score,
  • FROM cn_stock_factors AS sf JOIN cn_stock_factors_ta AS ta USING (date, instrument)
  • WHERE date > '2024-01-01'
  • """).df()
  • ```