我有使用db_link到MS SQL的表达式:
select b."Str" as "State" ,a."_Fld9059" as "Date" from
"_InfoRg9050"@SQLSERVER.UISLAB.COM a INNER JOIN
"EnumTexts"@SQLSERVER.UISLAB.COM b
on a."_Fld9052RRef" = b."_IDRRef"
where a."_Fld10998" = '1104000009' and
a."_Fld10998" = to_date(max(a."_Fld9059"),'dd.mm.yyyy')
order by a."_Fld9059" desc;
我想上传最大日期的值。有谁能够帮我 ? 当我运行此查询时,我收到ORA-00934错误。
答案 0 :(得分:2)
您遇到错误的直接原因是MAX()
子句中出现WHERE
。一种可能的解决方法(可能是您的意图)是使用WHERE
子句中的子查询来标识最大日期:
SELECT b.Str AS State,
a._Fld9059 AS Date
FROM _InfoRg9050 a
INNER JOIN EnumTexts b
ON a._Fld9052RRef = b._IDRRef
WHERE a._Fld10998 = '1104000009' AND
a._Fld10998 = (SELECT MAX(TO_DATE(_Fld9059, 'dd.mm.yyyy')) FROM _InfoRg9050)
ORDER BY a._Fld9059 DESC
但是,您不清楚为什么要将_InfoRg9050._Fld10998
与字符串'1104000009'
和进行比较。你需要自己解决这个问题,我相信会得到一个有意义的结果。
答案 1 :(得分:0)
感谢您的帮助。我懂了。
SELECT b."Str" AS "State"
FROM "_InfoRg9050"@SQLSERVER.UISLAB.COM a
INNER JOIN "EnumTexts"@SQLSERVER.UISLAB.COM b
ON a."_Fld9052RRef" = b."_IDRRef"
WHERE a."_Fld10998" = '1104000009' AND
a."_Fld9059" = (select MAX(a."_Fld9059") from "_InfoRg9050"@SQLSERVER.UISLAB.COM a
INNER JOIN "EnumTexts"@SQLSERVER.UISLAB.COM b
on a."_Fld9052RRef" = b."_IDRRef"
where a."_Fld10998" = '1104000009')
ORDER BY a."_Fld9059" DESC