2

Kdb calculates infinity for null column if group by is performed.

t:([]a: 1 1 2;b: 3 2 0n)
select min b by a from t

a       
1   2.0
2   ow

ow is infinity.

Is there any way I can get null(0n) for 2

Howli
  • 12,291
  • 19
  • 47
  • 72
Vikas
  • 118
  • 1
  • 8

3 Answers3

2

From Jeff Borror's q for mortals:

q)min 0N 5 0N 1 3                  / nulls are ignored
1
q)min 0N 0N                        / infinity if all null
0W

http://code.kx.com/q/ref/stats-aggregates/#min-minimum

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
nightTrevors
  • 639
  • 4
  • 11
  • 24
0

That's the expected result; you need to update afterwards:

update b:?[0w=b;0N;b] from select min b by a from t
Manish Patel
  • 4,411
  • 4
  • 25
  • 48
0

You should be careful when operating with nulls. Note the following

as additional info:

q)max 0N 0N
-0W
q)min 0N 0N
0W
q)0N+2
0N
q)sum 0N 2
2
q)sum 0N 0N
0
JPC
  • 1,891
  • 13
  • 29