# 重算等級
sql = """
with tmp as(
select case when dt=date('now') then 20
when dt>=date('now','-3 day') and dt<date('now') then 15
when dt>=date('now','-5 day') and dt<date('now','-1 day') then 10
when dt>date('now','-150 day') then 5 end as rk
from v_stock_news where news_type='利好'
union all
select code,case when dt=date('now') then 20
when dt>=date('now','-120 day') then -5
when dt>=date('now','-240 day') and dt<date('now','-120 day') then -3
when dt>date('now','-240 day') then -5 end
from v_stock_news where news_type='利空'
union all
select code,10 from stock_rk0
),t as(select code,sum(rk) rk from tmp group by code)
update stock_rank set rk=(select rk from t where stock_rank.code=t.code)
"""
cursor.execute(sql)
# 復制今日利好股票到剪貼板
C:\Users\Administrator\AppData\Local\Programs\Python\Python38\python.exe D:/stock/auto_huatai/spider.py
提示:當前環境pandas版本為0.25,get_price與get_fundamentals_continuously介面panel引數將固定為False
注意:0.25以上版本pandas不支持panel,如使用該資料結構和相關函式請注意修改
Traceback (most recent call last):
File "D:/stock/auto_huatai/spider.py", line 90, in <module>
cursor.execute(sql)
sqlite3.OperationalError: SELECTs to the left and right of UNION ALL do not have the same number of result columns
Process finished with exit code 1
這是卡在資料處理這了,都是最后一步,請教高人,懸賞啊!
uj5u.com熱心網友回復:
select case when dt=date('now') then 20when dt>=date('now','-3 day') and dt<date('now') then 15
when dt>=date('now','-5 day') and dt<date('now','-1 day') then 10
when dt>date('now','-150 day') then 5 end as rk
from v_stock_news where news_type='利好'
你這個結果集只有1個欄位,而后面2個結果集都有2個欄位,union all要求欄位數必須一致。
uj5u.com熱心網友回復:
改好了,多謝指點轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/241148.html
標籤:應用實例
上一篇:求SQL陳述句,跪求大神幫忙
