# MAX , MIN query

**URL:** <https://forum.kx.com/t/max-min-query/14201>\
**Category:** Academy Support\
**Tags:** imported\
**Created:** [April 21, 2025, 11:33am UTC](https://forum.kx.com/t/max-min-query/14201 "2025-04-21T11:33:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akash4](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/akash4/32/128_2.png) [@Akash4](https://forum.kx.com/u/Akash4)\
**Post date:** [April 21, 2025, 11:33am UTC](https://forum.kx.com/t/max-min-query/14201/1 "2025-04-21T11:33:59Z")

</div>

[https://learninghub.kx.com/forums/topic/max-min-query](https://learninghub.kx.com/forums/topic/max-min-query)

Hello all,

I am working on a problem with HDB where I have t+1 intraday data , and I want the&nbsp; MAX,MIN of each Symbol each mentioned by time shown in image , I can get data with interval using&nbsp; **XBAR** &nbsp;.But i want as per data logged in system.  
  
I attached image for reference  
  
EX.  
SYM&nbsp; &nbsp;Price&nbsp; &nbsp;time  
A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;53.4&nbsp; &nbsp; &nbsp;00:00:12.123  
A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;42.4&nbsp; &nbsp; &nbsp;00:00:13.465  
B&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;78.2&nbsp; &nbsp; &nbsp;&nbsp;00:00:15.123  
B&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;45.2&nbsp; &nbsp; &nbsp;&nbsp;00:00:16.123  
  
OUT

SYM&nbsp; Price&nbsp; time  
A&nbsp; &nbsp; &nbsp; &nbsp; 53.4&nbsp; &nbsp; 00:00:12.123  
A&nbsp; &nbsp; &nbsp; &nbsp; 53.4&nbsp; &nbsp; 00:00:13.465  
B&nbsp; &nbsp; &nbsp; &nbsp; 78.2&nbsp; &nbsp; &nbsp;00:00:15.123  
B&nbsp; &nbsp; &nbsp; &nbsp; 78.2 &nbsp; &nbsp; &nbsp;00:00:16.123  
  
Data is mixed and I have approach where I can use different variables and combine it,

but can we solve it in 1 query

&nbsp;

---

<div class="post-metadata">

**Author:** ![mwoods](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/mwoods/32/35_2.png) [@mwoods](https://forum.kx.com/u/mwoods)\
**Post date:** [April 22, 2025, 10:51am UTC](https://forum.kx.com/t/max-min-query/14201/2 "2025-04-22T10:51:43Z")

</div>

You can use maxs and mins to compute the running maximum/minimum by sym.

```
q)t1:([]sym:`A`A`B`B;price:53.4 42.4 78.2 45.2;time:00:00:12.123 00:00:13.465 00:00:15.123 00:00:16.123)
```

```
q)t1
sym price time        
----------------------
A 53.4 00:00:12.123
A 42.4 00:00:13.465
B 78.2 00:00:15.123
B 45.2 00:00:16.123
```

```
q)update maxPrice:max maxs price,minPrice:min mins price by sym from t1
sym price time maxPrice minPrice
----------------------------------------
A 53.4 00:00:12.123 53.4 42.4
A 42.4 00:00:13.465 53.4 42.4
B 78.2 00:00:15.123 78.2 45.2
B 45.2 00:00:16.123 78.2 45.2   
```
