max and min scan x partition y

19 May 2014 | , , ,
Share on:

maximum scan readout

I’m joining idioms 2 and 3 here as it’s important to see the pattern.

q)x:1 1 0 0 0 1 0 0 1 1
q)y:3 4 8 2 5 6 9 4 5 4
q)maxs each(where x)_y
,3
4 8 8 8
6 9 9
,5
,4
q)raze maxs each(where x)_y
3 4 8 8 8 6 9 9 5 4
q)max each(where x)_y
3 8 9 5 4
q)mins each(where x)_y
,3
4 4 2 2
6 6 4
,5
,4
q)raze mins each(where x)_y
3 4 4 2 2 6 6 4 5 4
q)raze min each(where x)_y
3 2 4 5 4
q)min each(where x)_y
3 2 4 5 4
q)

and when working with tables you’d do something like:

q)t:([]x;y)
q)t
x y
---
1 3
1 4
0 8
0 2
0 5
1 6
0 9
0 4
1 5
1 4
q)select mins y by sums x from t
x| y
-| -------
1| ,3
2| 4 4 2 2
3| 6 6 4
4| ,5
5| ,4
q)select min y by sums x from t
x| y
-| -
1| 3
2| 2
3| 4
4| 5
5| 4
q)value exec min y by sums x from t
3 2 4 5 4
q)value exec mins y by sums x from t
,3
4 4 2 2
6 6 4
,5
,4
q)raze value exec mins y by sums x from t
3 4 4 2 2 6 6 4 5 4
q)

SUGGESTED ARTICLES

Kdb+ Transitive Comparisons

6 Jun 2018 | , ,

By Hugh Hyndman, Director, Industrial IoT Solutions. A direct comparison of the performance of kdb+ against InfluxData and, by transitivity, against Cassandra, ElasticSearch, MongoDB, and OpenTSDB

Kx provides rapid access to unstructured data

Insights into kdb+ 3.6

5 Jun 2018 | , ,

At Kx25, the international kdb+ user group conference held on May 18th, we released kdb+ version 3.6. With this release, we are opening up new possibilities for kdb+ application developers.
It provides a lot of new capabilities and streamlines previously complex processes so that programmers will be able to take a simpler approach to writing systems compared to what they did in the past.