oracle10g中的group by子句
我正在使用 oracle 10g 并编写了这样的查询:
SELECT presenttime,
employeeid
FROM mobilelocation
WHERE presentdate = '31-10-2011'
GROUP BY employeeid;
产生错误消息
ORA-00979: not a GROUP BY expression
但是在删除此 group 子句后返回结果而没有任何类似这样的错误,
PRESENTTIME EMPLOYEEID
23:25 12304
23:48 12305
我的 group by 子句有什么问题,并建议我如何使用 order by 子句也
I am using oracle 10g and wrote a query like this:
SELECT presenttime,
employeeid
FROM mobilelocation
WHERE presentdate = '31-10-2011'
GROUP BY employeeid;
resulting an error message
ORA-00979: not a GROUP BY expression
But upon removing this group clause returining the result without any errors like this,
PRESENTTIME EMPLOYEEID
23:25 12304
23:48 12305
What is the problem with my group by clause and also suggest me how to use order by clause also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GROUP BY
意味着您希望针对每个EmployeeID
值将表中的多行聚合到一行中。如果这是您的目标,您需要在不作为分组依据的列上指定聚合函数。例如,如果您想要每个EmployeeID
的最早PresentTime
值,您可以执行类似的操作GROUP BY
implies that you want to aggregate multiple rows from the table into a single row for everyEmployeeID
value. If that is your goal, you'd need to specify an aggregate function on the columns that you are not grouping by. If you want the earliestPresentTime
value for eachEmployeeID
, for example, you'd do something like您需要按presenttime、employeeID
以及order by 进行分组;它类似于分组依据。
按员工 ID 排序、当前时间(描述)
如果未定义聚合(最小值、最大值、总和、计数等),则选择部分中的任何项目都必须位于按部分分组中
You need to group by both presenttime, employeeID
As far as order by; its similar to group by.
Order by employeeID, presentTIme (desc)
any item in the select portion must be in the group by portion if an aggregrate wasn't defined (min, max, sum, count, etc.)