【发布时间】:2020-05-11 19:48:11
【问题描述】:
我正在尝试用 SQL 编写一个过程。 在将所有日期条目与传递的输入参数匹配后,我想从表中打印带有“最大分数”的记录。 现在,代码只打印与指定日期对应的所有记录。 我不确定在这种情况下如何使用 MAX()。
/* =========================================================
Procedure to find the Highest Movie Rating on a particular date.
Given, an inpDate (input Date) it first looks up all Movie Reviews
of that particular date.
Then, it checks a StandardizedReviews Table (sTbl) and
finds the MAXIMUM adjusted_score with the
Highest Review Score (the variable adjusted_score)
========================================================= */
Use StandardizedReviews
Drop Procedure if exists HighestReview;
GO
CREATE PROCEDURE HighestReview @inpDate DATE AS (
SELECT sTbl.adjusted_score "Max Score"
FROM dbo.StandardizedReviews sTbl
WHERE CAST(sTbl.date as DATE) = CAST(@inpDate as DATE)
GROUP BY sTbl.date, sTbl.adjusted_score
)
GO
exec HighestReview '2020-03-05'
GO
现在,我的输出看起来像:
但我希望它只显示得分为 100 的记录。 谢谢。
【问题讨论】:
标签: sql select max where-clause