[英]math and to_char
Display branch name, number of employees as Headcount, total Salary as Payroll, and average salary as "Average Salary" for branches that have more than one employee. 对于拥有多个员工的分支机构,显示分支机构名称,员工数作为员工总数,工资总额作为薪资,平均工资作为“平均工资”。 Format all dollar amounts with the "$" format. 用“ $”格式格式化所有美元金额。
Below is my code to answer this query however I am receiving an invalid number error. 以下是我的代码来回答此查询,但是我收到无效的数字错误。
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;
You've got TO_CHAR
and AVG/SUM
reversed: 您已将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
You need to have TO_CHAR
on the "outside" of the stacked function calls - otherwise you're attempting to compute the average and sum of a character string containing a '$'
, and Oracle quite rightly pitches a fit about $
not being a valid digit. 您需要在堆栈函数调用的“外部”使用TO_CHAR
否则,您将尝试计算包含'$'
字符串的平均值和之和,Oracle正确地将$
设置为有效值数字。
Best of luck. 祝你好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.