Using the DISTINCT keyword causes this error: not a SELECTed expression(使用 DISTINCT 关键字会导致此错误:not a SELECTed expression)
问题描述
我有一个类似这样的查询:
I have a query that looks something like this:
SELECT DISTINCT share.rooms
FROM Shares share
left join share.rooms.buildingAdditions.buildings.buildingInfoses as bi
... //where clause omitted
ORDER BY share.rooms.floors.floorOrder, share.rooms.roomNumber,
share.rooms.firstEffectiveAt, share.shareNumber, share.sharePercent
导致以下异常:
Caused by: org.hibernate.exception.SQLGrammarException: ORA-01791: not a SELECTed expression
如果我删除 DISTINCT 关键字,查询将正常运行.如果我删除 order by 子句,查询将毫无问题地运行.不幸的是,我似乎无法获得没有重复的有序结果集.
If I remove the DISTINCT keyword, the query runs without issue. If I remove the order by clause, the query runs without issue. Unfortunately, I can't seem to get the ordered result set without duplicates.
推荐答案
您正在尝试使用未计算的列对结果进行排序.如果您在那里没有 DISTINCT ,这不会成为问题,但是由于您的查询基本上仅按 share.rooms 列分组,因此如何对其进行排序结果集与其他列可以具有相同 share.rooms 的多个值?
You are trying to order your result with columns that are not being calculated. This wouldn't be a problem if you didn't have the DISTINCT there, but since your query is basically grouping only by share.rooms column, how can it order that result set with other columns that can have multiple values for the same share.rooms one?
这篇关于使用 DISTINCT 关键字会导致此错误:not a SELECTed expression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 DISTINCT 关键字会导致此错误:not a SELECTed expression
基础教程推荐
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 无法解决整理冲突 2021-01-01
