2 回答
TA贡献1818条经验 获得超3个赞
按最新开始日期(降序)排序并选择前 1!
string agentIdSubQuery = "AGENT_ID " +
"FROM " +
"KS_DRIFT.V_AGENT_ALLOCATION " +
"WHERE " +
"LENGTH(AGENT_INITIALS) < 5 " +
" AND ROWNUM = 1 " +
" ORDER BY ALLOCATION_START DESC";
编辑,将 Top 1 更改为 Rownum = 1,对于 Oracle 语法
TA贡献1848条经验 获得超10个赞
您的错误消息显示了最终生成的 SQL:
{"在执行 SQL 查询时发生错误:SELECT age1.* FROM KS_DRIFT.V_AGENT_ALLOCATION age1 INNER JOIN (SELECT max(DISTINCT AGENT_ID FROM KS_DRIFT.V_AGENT_ALLOCATION WHERE LENGTH(AGENT_INITIALS) < 5 AND '2018-ALLOCATION_END1 AND '2018-ALLOCATION_END1 INNER JOIN) AND (UPPER(AGENT_INITIALS) = 'JKKA')) age2 ON age1.AGENT_ID = age2.AGENT_ID ORDER BY AGENT_INITIALS。"}
如果将其格式化以使其可读,则会得到:
select age1.*
from ks_drift.v_agent_allocation age1
inner join
( select max(distinct agent_id
from ks_drift.v_agent_allocation
where length(agent_initials) < 5
and '2018-08-15' between allocation_start and allocation_end
and (upper(agent_initials) = 'JKKA') ) age2
on age1.agent_id = age2.agent_id
order by agent_initials
应该跳出两个语法问题:
后面缺少一个右括号
max(distinct agent_id
(distinct
也是多余的)日期文字缺少它的
date
关键字——它应该是date '2018-08-15'
(或者更好的是,一个绑定变量)。
周围的括号(upper(agent_initials) = 'JKKA')
是多余的,但也许它们来自您的生成器逻辑,最容易保留它们。
不过,我不确定这与您的“最新分配部门”要求有何关系。一些示例数据(不是屏幕截图)会有所帮助。
- 2 回答
- 0 关注
- 185 浏览
添加回答
举报