MAX and MIN gives Timeout, AVG not

Have a strange problem.
A large table (>1tb), select statement of a number of columns return about 30 rows.
Key is a combination of a timestamp and an string id.

I put MAX on those columns and one of the columns causes a time out.
Have isolated this to one particular column.
MIN also gives a timeout but AVG works.
The other columns works ok.

In another database with an identical table (but not that large) it works ok.
Any ideas will be much appreciated
/Peo

What is the query that returns 30 rows look like for example the where clause

select MAX(EP_COMP) AS EP_COMP
From [LOGGEDVALUES_SI] 
Where [PAID]='003411' 
and [SMPTIME] > '2018-11-20 16:00:00' 
and [SMPTIME] < '2018-11-20 17:00:00';

If I change to AVG or SUM it works ok, also with other columns (also float columns)

MAX() would require a sort, AVG and SUM would not.

Can you post the table definition, CREATE TABLE ..., including all indexes.

What happens if you try this


select MAX(EP_COMP) AS EP_COM
From (
Select ep_comp
From [LOGGEDVALUES_SI]
Where [PAID]='003411' and [SMPTIME] > '2018-11-20 16:00:00' and [SMPTIME] < '2018-11-20 17:00:00') big