在我的数据库中,我有以下行和列:https : //i.imgur.com/ktUZY9d.jpg
我的问题是同一个员工有 3 个不同的部门,但他目前只活跃在 1 个部门。如何更改此 SQL 语句以仅包含他所在的最新部门,从 2018 年开始到 2100 年结束,如ALLOCATION_START 和 ALLOCATION_END?
询问
string agentIdSubQuery = "SELECT DISTINCT " +
"AGENT_ID " +
"FROM " +
"KS_DRIFT.V_AGENT_ALLOCATION " +
"WHERE " +
"LENGTH(AGENT_INITIALS) < 5";
if(queryParams.SnapshotDate.HasValue)
agentIdSubQuery += " AND " + OracleConversion.ToOracleDate(queryParams.SnapshotDate) + " BETWEEN ALLOCATION_START AND ALLOCATION_END";
更新:
尝试了很多不同的解决方案,但每次都崩溃,当我运行调试器时,在这个方法中进一步向下这个查询导致我崩溃:
string sql = "SELECT " +
"age1.* " +
"FROM " +
"KS_DRIFT.V_AGENT_ALLOCATION age1 " +
"INNER JOIN " +
"(" + agentIdSubQuery + ") age2 ON age1.AGENT_ID = age2.AGENT_ID " +
"ORDER BY " +
"AGENT_INITIALS";
错误信息:
{"在执行 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 '2015'ALLOCETATION_START- AND (UPPER(AGENT_INITIALS) = 'JKKA')) age2 ON age1.AGENT_ID = age2.AGENT_ID ORDER BY AGENT_INITIALS。"}
也给了我一个内心的例外:
{"ORA-00904: \"AGE2\".\"AGENT_ID\": ugyldig identifikator"}
泛舟湖上清波郎朗
慕桂英546537
相关分类