pivot by的奇怪问题

select value from loadTable('dfs://K_FACTOR_LONG','factor_k_long') where (securityid = `US_MSFT) and (tradetime between timestamp(2023.11.02):timestamp(2023.12.03) ) pivot by tradetime,securityid,factorname
上面这个执行后,11月30和12月1日的数据都是空的(K_FACTOR_LONG是在12月1的有内容的)11月02到11月29都是有内容的。 

但把起始时间改成11月30,然后最终结果就有内容。 我不理解啊, 这个pivotby为什么会出现这种情况?  难道必须一天一天的去pivotby?
select value from loadTable('dfs://K_FACTOR_LONG','factor_k_long') where (securityid = `US_MSFT) and (tradetime between timestamp(2023.11.30):timestamp(2023.12.03) ) pivot by tradetime,securityid,factorname
请先 登录 后评论

3 个回答

Gaxia320

试一下分两部

t=select tradetime,securityid,factorname,value from loadTable('dfs://K_FACTOR_LONG','factor_k_long') where (securityid = `US_MSFT) and (tradetime between timestamp(2023.11.02):timestamp(2023.12.03) )

select value from t pivot by tradetime,securityid,factorname

请先 登录 后评论
wfHuang

能否备份下US_MSFT这个股票的数据上传下

请先 登录 后评论
谭华

pivot by 应该不会出现题主所出现的问题。

代码复现如下,不会出现数据为空的情况。


数据:

n=1000000:
ID=rand(150, n)
dates=2017.08.07..2017.08.11
date=rand(dates, n)
x=rand(`a`b`c`d`e, n)
t=table(ID, date, x)
dbDate = database(, VALUE, 2017.08.07..2017.08.11)
dbID = database(, RANGE, 0 50 100 150)
db = database("dfs://compoDB", COMPO, [dbDate, dbID])
pt = db.createPartitionedTable(t, `pt, `date`ID)
pt.append!(t);

pivot by 语句:

select x from loadTable("dfs://compoDB", "pt") 
where (ID = 48) and (date between date(2017.08.07):date(2017.08.11) ) pivot by date,ID,x

执行结果:

attachments-2024-01-eiZJ0WfS65b6f8f1981cc.png

请先 登录 后评论
  • 3 关注
  • 0 收藏,412 浏览
  • eric 提出于 2023-12-02 17:51

相似问题