您好我有一个select子查询,它具有来自子查询的列数据,以便从其他表中获取按日期排序的第一个数据,如果子查询没有按语法排序,则它是正常的。但是,当子查询使用它的顺序时,会给出缺少右括号错误。
Select ...,
A.number,
(select K.created_by_user_id from
(SELECT L.created_by_user_id
FROM user_content L
WHERE (
L.content LIKE '%message%'
OR L.content LIKE '%response%'
)
AND L.number = A.number
ORDER BY created_by_date
) K
where ROWNUM = 1) as first_user
FROM ...
我也尝试单独查询rownum,如下面的查询和顺序,它仍然得到错误无效的标识符。
var acceptedHitchRequest = await _acceptedRequestRepository.GetAll()
.Include(p => p.HitchRequest)
.Include(p => p.CarparkRequest)
.Include(p => p.HitchRequest.User)
.Include(p => p.CarparkRequest.User)
.Where(p => (input.HitchRequestId.HasValue ? p.HitchRequest.Id == input.HitchRequestId : p.CarparkRequest.Id == input.CarparkRequestId)
&& p.IsActive).FirstOrDefaultAsync();
if (input.HitchRequestId.HasValue && acceptedHitchRequest.HitchRequest.CreatorUserId == AbpSession.UserId)
数据库引擎正在使用oracle 请帮忙。谢谢。
答案 0 :(得分:0)
我通过单独查询rownum并将数字移动到上部查询的位置来解决。至少查询效果很好,并给出正确的结果。但也许这个查询可以改进性能。
Select ...,
A.number,
(select K.created_by_user_id from
(SELECT L.created_by_user_id
FROM user_content L
WHERE (
L.content LIKE '%message%'
OR L.content LIKE '%response%'
)
ORDER BY created_by_date
) K
where ROWNUM = 1 AND L.number = A.number) as first_user
FROM ...