# max and min scan x partition y

##### 19 May 2014 | Kdb+, kx, max, partition
Share on:

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)```

Kx® and kdb+ are registered trademarks of Kx Systems, Inc., a subsidiary of First Derivatives plc.

### SUGGESTED ARTICLES

#### Head of Products, Solutions and Innovation at Kx on Product Design and the Vision for the Future

##### 16 Mar 2018 | CAT, financial services, Kdb+, MiFID II

As the SVP of Products, Solutions and Innovation at Kx Systems, James Corcoran is part of a new chapter in software development at Kx. Since joining Kx parent First Derivatives as a financial engineer in 2009, James has worked around the world building enterprise systems at top global investment banks before moving to the Kx product team in London. James sat down with us recently to discuss his perspective on product design and our technology strategy for the future.

#### Kdb+ Utilities: Essential utility for identifying performance problems

##### 28 Feb 2018 | APL, Kdb+

If you are a kdb+/q developer, you will find the utilities created by Kx Managing Director and Senior Solution Architect Leslie Goldsmith to be a valuable resource. The “Kdb+ Utilities” series of blog posts gives a quick introduction to the utilities, available at Leslie Goldsmith’s GitHub. In this third part of the series we look at Leslie’s qprof, which allows a programmer to drill down into q functions or applications to inspect performance and CPU usage in a fine-grained fashion.

#### Kdb+ Utilities: Q code Workspace Utilities

##### 6 Feb 2018 | APL, Kdb+, kx

If you are a kdb+/q developer, you will find the workspace utilities created by Kx Managing Director and Senior Solution Architect Leslie Goldsmith to be a valuable resource. This is the first in a series of blog posts that give a quick introduction to several utilities available at Leslie Goldsmith’s GitHub. In this part of the series we look at an essential tool which contains routines for summarizing and searching the contents of a workspace, ws.