尝试从每个唯一年份中获取球员的唯一体重和身高,在SQL中。

huangapple go评论44阅读模式
英文:

Trying to get unique weight and height of players from each unique year in SQL

问题

这是问题。

显示海盗队(SEA)每年比赛的平均体重和身高。
包括年份、平均体重和平均身高,按年份顺序排列,从最近的年份开始。

SELECT yearID, AVG(weight) as 平均体重, AVG(height) as 平均身高
FROM [TWalls_W23].[dbo].[PlayersAndTeams]
WHERE teamID = 'SEA' 
GROUP BY yearID

我已经写出了上面的代码,但它没有显示每个唯一年份的平均体重或身高。

英文:

尝试从每个唯一年份中获取球员的唯一体重和身高,在SQL中。
This is the question.

Display the average weight and height of the Mariners (SEA) for each year they played.
Include the year, average weight, and average height in year order starting with the most
recent year

SELECT yearID, AVG(weight) as AverageWeight, AVG(height) as AverageHeight
FROM [TWalls_W23].[dbo].[PlayersAndTeams]
where teamID = 'SEA' 
group by yearID

I've written that above but it's not showing me the average weight or height from each unique year.

答案1

得分: 1

SELECT yearID, AVG(CAST(weight AS DECIMAL)) as 平均体重, AVG(CAST(height AS DECIMAL)) as 平均身高
FROM [TWalls_W23].[dbo].[PlayersAndTeams]
WHERE teamID = 'SEA'
GROUP BY yearID

英文:

You need to cast to decimal.

SELECT yearID, AVG(CAST(weight as DECIMAL)) as AverageWeight, AVG(CAST(height AS DECIMAL)) as AverageHeight
FROM [TWalls_W23].[dbo].[PlayersAndTeams]
where teamID = 'SEA' 
group by yearID

答案2

得分: 0

您的查询没有问题,因此您的问题出现在您的数据中。

英文:

Your query is ok, so your problem come from your data.

huangapple
  • 本文由 发表于 2023年2月8日 16:38:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75383131.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定