Reputation: 5
I'm trying to query min, max and avg between two dates, that I got from [DATA].
SELECT
MIN([INDEX]) as MIN,
AVG([INDEX]) as avg,
MAX([INDEX]) as max
FROM [data].[dbo].[db_DATA]
I tried with the following sql query, but didn't work too.
SELECT
MIN([INDEX]) as MIN,
AVG([INDEX]) as avg,
MAX([INDEX]) as max
FROM [data].[dbo].[db_DATA]
having MIN([INDEX]) between '2017-02-20' AND '2017-02-25'
Upvotes: 0
Views: 173
Reputation: 956
As you do not GROUP BY put it in the where clause instead of HAVING. Also remove MIN() because if min is between then max is also and avg is also.
SELECT
MIN([INDEX]) as MIN,
AVG([INDEX]) as avg,
MAX([INDEX]) as max
FROM [data].[dbo].[db_DATA]
WHERE [INDEX] between '2017-02-20' AND '2017-02-25'
Upvotes: 2
Reputation: 442
the dates is always with '#' if you are working with Ms-access
try like this
SELECT
MIN([INDEX]) as MIN,
AVG([INDEX]) as avg,
MAX([INDEX]) as max
FROM [data].[dbo].[db_DATA]
having MIN([INDEX]) between #02/20/2017# AND #02/25/2017#
Upvotes: 1