英文:
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
我已经写出了上面的代码,但它没有显示每个唯一年份的平均体重或身高。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论