[英]How to get min and max in one sql query?
what will be the query to get min and max at once I am getting errors in this query一次获取最小值和最大值的查询将是什么我在此查询中遇到错误
router.get('/min/:date', (req, res) => {
const date = req.params.date;
console.log(typeof date);
connection.query(
`select max(temperature) as highesttemperature; select min(temperature) as lowesttemperature from weather_data where dt=?`,
[date],
(err, results, field) => {
if (err) {
console.log(err);
} else {
res.status(200).send(results);
console.log(results);
}
}
);
});
You can have both in the same query, no need for a second select:您可以在同一个查询中同时拥有两者,无需第二个 select:
select max(temperature) as highesttemperature,
min(temperature) as lowesttemperature
from weather_data
where dt=?
The error is in your first query, there is no FROM
clause.错误出现在您的第一个查询中,没有FROM
子句。
Try this尝试这个
SELECT MIN(temperature), MAX(temperature) FROM weather_data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.