oracle10g中的group by子句

发布于 2024-12-14 20:15:48 字数 441 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凡尘雨 2024-12-21 20:15:48

GROUP BY 意味着您希望针对每个 EmployeeID 值将表中的多行聚合到一行中。如果这是您的目标,您需要在不作为分组依据的列上指定聚合函数。例如,如果您想要每个 EmployeeID 的最早 PresentTime 值,您可以执行类似的操作

SELECT EmployeeID, MIN(PresentTime) earliestPresentTime
  FROM mobileLocation
 WHERE PresentDate = date '2011-10-31'
 GROUP BY EmployeeID

GROUP BY implies that you want to aggregate multiple rows from the table into a single row for every EmployeeID 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 earliest PresentTime value for each EmployeeID, for example, you'd do something like

SELECT EmployeeID, MIN(PresentTime) earliestPresentTime
  FROM mobileLocation
 WHERE PresentDate = date '2011-10-31'
 GROUP BY EmployeeID
单身狗的梦 2024-12-21 20:15:48

您需要按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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文