sql - 数学和 to_char
问题描述
对于拥有超过一名员工的分支机构,将分支机构名称、员工人数显示为 Headcount、总工资显示为 Payroll、平均工资显示为“Average Salary”。使用“$”格式格式化所有美元金额。
以下是我回答此查询的代码,但是我收到了无效号码错误。
select br_branchname, count (st_staffno) as "Headcount",
sum(to_char (st_salary, '$99,999.00')) as "Payroll",
avg(to_char (st_salary, '$99,999.00')) as "Average Salary"
from branch join staff
on st_br_branchno = br_branchno
group by br_branchname
having count (st_staffno) > 1;
解决方案
你已经得到TO_CHAR
并AVG/SUM
扭转了:
select br_branchname,
count (st_staffno) as "Headcount",
TO_CHAR(SUM(st_salary), '$99,999.00') as "Payroll",
TO_CHAR(AVG(st_salary), '$99,999.00') as "Average Salary"
from branch
INNER join staff
on st_br_branchno = br_branchno
group by br_branchname
having count (st_staffno) > 1
您需要TO_CHAR
在堆叠函数调用的“外部”进行 - 否则您将尝试计算包含 a 的字符串的平均值和总和,而 Oracle 非常正确地提出了一个关于不是有效数字'$'
的拟合。$
祝你好运。
推荐阅读
- java - 选择排序不排序Java
- vba - 隐藏要通过邮件发送的列 excel vba
- cordova - Ionic - 内联日期时间选择器
- javascript - ECMAScript 对象扩展/休息 - 一次分配给多个属性
- ios - 强制 iOS 应用使用私有 API 在前台打开
- javascript - 仅当在循环内调用类方法时,Javascript 执行中断并显示 TypeError 消息“无法读取未定义的属性 'refcount'”
- python - Kivy : Apply function variables to Button Text
- tensorflow - 用于对象检测的 Tensorboard eval.py IOU
- python - API Gateway 中的 AWS Lambda 集成响应 - {"message": "Internal server error"}
- python - Python:从字典列表中的值生成特定组合以进行时间表规划