SQL组函数查询?

时间:2017-10-20 09:21:42

标签: sql oracle

下面的sql代码给了我ora - Invalid Number错误。 我该如何解决这个问题? 我猜它与按功能分组有关。

SELECT SUM(RAT_CCY_SELL)/COUNT(dat_last_upd) 
FROM  RD_FCY_RATE_HIST  
WHERE cod_ccy ='EUR' 
AND   to_char( pk_ba_global.dat_process,'mm') - to_char(DAT_LAST_UPD,'mm')='1';

2 个答案:

答案 0 :(得分:0)

我认为你应该在这里使用平均函数select * from one t1 join six t6 ON exists ( select * from two t2 join three t3 on t3.two_id = t2.two_id join four t4 on t4.three_id = t3.three_id join five t5 on t5.five_id = t4.five_id where t2.one_id = t1.one_id and t5.six_id = t6.six_id );

AVG

我在这里假设列SELECT AVG(RAT_CCY_SELL) FROM RD_FCY_RATE_HIST WHERE cod_ccy = 'EUR' AND TO_CHAR(SYSDATE, 'yyyy-mm') = TO_CHAR(DAT_LAST_UPD, 'yyyy-mm') 包含每条记录的日期,用于确定哪些数据与当前月份相对应。如果没有,则替换该列。

答案 1 :(得分:0)

我认为错误是因为减去了两个字符串。

link的一些信息正在关注

Oracle / PLSQL:ORA-01722错误消息

<强>原因

 You executed a SQL statement that tried to convert a string to a number, 
but it was unsuccessful.

解决

The option(s) to resolve this Oracle error are:

Option #1
----------
Only numeric fields or character fields that contain 
numeric values can be used in arithmetic operations.
Make sure that all expressions evaluate to numbers.

Option #2
-----------
If you are adding or subtracting from dates, 
make sure that you added/substracted a numeric value from the date.