简体   繁体   English

在where子句中使用sum函数

[英]Use sum function in where clause

I'm working with oracle fusion and one of the apps I'm working with (value-sets) does not allow me to use functions in the select statement and the from section has a 200 character limit. 我正在使用oracle融合,并且正在使用的其中一个应用(值集)不允许我在select语句中使用函数,并且from部分的字符数限制为200。

This query gives me what I want but I cant use the sum with the select- 这个查询给了我我想要的东西,但是我不能将总和与select-

SELECT SUM(d.ABS_UNITS) from PER_ALL_PEOPLE_F b, ANC_ABSENCE_PLANS_F_TL c, 
ANC_PER_ABS_PLAN_ENTRIES d
WHERE 
d.PERSON_ID = b.PERSON_ID
AND c.ABSENCE_PLAN_ID = d.ABSENCE_PLAN_ID
AND c.name = 'FMLA LWOP'
and d.start_date between '2017-04-02' and '2017-04-15'
AND b.PERSON_NUMBER = p_num

I also tried this but had the character limit issue - 我也尝试过此操作,但遇到字符限制问题-

Select aa.bb from
(SELECT SUM(d.ABS_UNITS) as bb from PER_ALL_PEOPLE_F b, 
ANC_ABSENCE_PLANS_F_TL c, ANC_PER_ABS_PLAN_ENTRIES d
WHERE 
d.PERSON_ID = b.PERSON_ID
AND c.ABSENCE_PLAN_ID = d.ABSENCE_PLAN_ID
AND c.name = 'FMLA LWOP'
and d.start_date between '2017-04-02' and '2017-04-15'
AND b.PERSON_NUMBER = p_num
) aa

This approach is what I've been trying to work with putting the sum in the where clause but it's not returning anything. 这种方法是我一直试图将总和放在where子句中的方法,但是它没有返回任何内容。

Select
d.ABS_UNITS
FROM
PER_ALL_PEOPLE_F b, ANC_ABSENCE_PLANS_F_TL c, ANC_PER_ABS_PLAN_ENTRIES d
WHERE 
d.PERSON_ID = b.PERSON_ID
AND c.ABSENCE_PLAN_ID = d.ABSENCE_PLAN_ID
AND c.name = 'FMLA LWOP'
AND b.PERSON_NUMBER = pnum
and d.start_date between '2017-04-02' and '2017-04-15'
AND d.ABS_UNITS = (SELECT SUM(d.ABS_UNITS) from PER_ALL_PEOPLE_F b, 
ANC_ABSENCE_PLANS_F_TL c, ANC_PER_ABS_PLAN_ENTRIES d
WHERE 
d.PERSON_ID = b.PERSON_ID
AND c.ABSENCE_PLAN_ID = d.ABSENCE_PLAN_ID
AND c.name = 'FMLA LWOP'
and d.start_date between '2017-04-02' and '2017-04-15'
AND b.PERSON_NUMBER = pnum
)

Any input and advice would be greatly appreciated. 任何意见和建议将不胜感激。

I have not work with fusion apps. 我尚未使用融合应用程序。
If I don't understand wrong you have limits for character limit and functions in select. 如果我不理解错误,则可以选择字符数和功能。

Your 'where' clause is long considering your character limit. 您的“ where”子句长期以来一直在考虑您的字符数限制。 You can shorten it using ALIAS for columns and tables in database level. 您可以使用ALIAS在数据库级别的列和表中将其缩短。 Then customize your query. 然后自定义查询。

Thanks for all the input I really appreciate it. 感谢您的所有输入,我非常感激。 I found a work around, Oracle Fusion has hidden functions in the script language I was working with that are not documented but can be found through sql. 我找到了一种解决方法,Oracle Fusion在使用的脚本语言中隐藏了功能,这些功能未记录,但可以通过sql找到。 Very frustrating, but thanks for all the feed back 非常令人沮丧,但感谢您的所有反馈

You can't use aggregate functions (such as SUM ) in WHERE clause, because WHERE limits rows physically. 您不能在WHERE子句中使用聚合函数(例如SUM ),因为WHERE物理上限制行。 You shall aggregate in GROUP BY clause to logically limit output. 您应在GROUP BY子句中进行汇总,以在逻辑上限制输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM