我正在尝试查询从[数据]获得的两个日期之间的最小值,最大值和平均值。
SELECT
MIN([INDEX]) as MIN,
AVG([INDEX]) as avg,
MAX([INDEX]) as max
FROM [data].[dbo].[db_DATA]
我尝试使用以下sql查询,但也无法正常工作。
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'
答案 0 :(得分:2)
因为您没有GROUP BY,所以将其放在where子句中而不是HAVING中。还要删除MIN(),因为如果min介于之间,则max也为avg也为。
function resetDB() {
console.log("resetDB called")
command =
"mysql" +
" --defaults-extra-file=" + mysql_conf_file +
" --host " + process.env['MYSQL_HOSTNAME'] +
" -D fundme < " + testing_db_file_location;
cp.execSync(command);
console.log("resetDB finished")
}
答案 1 :(得分:1)
如果您使用Ms-access,则日期始终带有“#”
尝试这样
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#