选择,平均语句不起作用 [英] select, avg statement not working

查看:39
本文介绍了选择,平均语句不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 Employee 的表,上面有大约 17 个不同的列.其中一列称为年龄.我想写一个声明,该声明将获得声明中所有具有 AS 的员工的平均年龄.这是我写的声明,不幸的是我继续收到错误消息.另外,我是这方面的新手,所以请不要打我……哈哈.

I have a table called Employee with about 17 different columns on it. One of those columns is called age. I am suppose to write up a statement that will get the average age of all the employees with an AS in the statement. Here is the statement I have written up and unfortunately I continue to get an error message. Also, I am new at this so please don't beat me to hard...lol.

SELECT AVG(Age) AS Average_Age FROM Employee

我收到以下错误..

msg 8117,状态 16,第 1 行操作数平均值的无效语法.

msg 8117, state 16, line 1 invalid syntax for operand avg.

我相信消息告诉我平均值正在尝试计算,但无法执行.

I believe the message is telling me that the avg is trying to calculate, but cannot do it.

为什么我在 youtube 视频上看到了这个,而且它对创建它的人来说效果很好?虽然我做了完全相同的陈述,但我错了……有人可以解释一下吗?

Why did I see this done on a youtube video and it work perfectly for the person who created it? While I did the same exact statement I got it wrong...can someone explain that?

根据评论更新:

错误信息:

操作数数据类型 varchar 对于 avg 运算符无效.

Operand data type varchar is invalid for avg operator.

推荐答案

如果 age 是 varchar 列你可以试试

If age is a varchar column you can try

SELECT AVG(cast(Age as int)) AS Average_Age FROM Employee

(但您可能需要考虑更改数据类型)

( but you may want to think about changing the datatype )

这篇关于选择,平均语句不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆