Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

count(1)和 count(*) 的结果不一样

请问一下,DolphinDB的sql查询是不是标准sql有些区别?如下图所示,
count(1)和 count(*) 的结果不一样。
image.png


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

1 Answer

0 votes
by (71.8m points)

count(*)返回的是所有数据的行数,count(1)返回的是分区数。这个分区数是已写入实际数据的分区数,而不是所有已建立的分区数。比如下列代码我建库时创建了30个按天值分区,然后往2017.08.07和2017.08.08这2个分区写入了1000条数据:

n=1000
dates=2017.08.07..2017.08.08
date=rand(dates, n)
x=rand(10.0, n)
t=table(date, x)
db = database("dfs://testdb", VALUE, 2017.08.01..2017.08.30)
pt = db.createPartitionedTable(t, `pt, `date) 

pt.append!(t)

然后查询:

select count(x) from pt;//1000 
select count(1) from pt//2

第一个查询返回记录数1000,第二个查询返回已有实际数据的分区数2。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...