Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

DolphinDB选择性去重

我有一个表格如下:

id=rand(`A`B,100)
item= rand(10,100)
date= rand(2020.10.11..2020.10.21,100)
t=table(id,item,date)
t.sortBy!(`date)

id item date      
-- ---- ----------
A  7    2020.10.11
B  8    2020.10.11
A  4    2020.10.11
B  2    2020.10.12
B  2    2020.10.12
B  7    2020.10.12
B  7    2020.10.12
B  5    2020.10.12
...

我的需求是:在相同id和相同date的条件下,只提取item最大值。
如:

id item date      
-- ---- ----------
A  7    2020.10.11
B  8    2020.10.11
B  7    2020.10.12
...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

两种方法:

select * from t  context by date, id csort item limit -1

select top 1 * from t context by date, id csort item desc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...