简体   繁体   English

oracle group by一次得到一个组

[英]oracle group by get a group at a time

My Data looks like this 我的数据看起来像这样

 1. Fname    Lastname   DOB       ADDR   SEX   SSN 
 2. Sanal    Pillai    12/11/85   Pune   M     - 
 3. Sunil    Pillai    05/11/80   Pune   M     123456 
 4. Anju     Pillai    12/11/85   Pune   F     345679 
 5. Arachana Pillai    05/11/80   Pune   M  

- --

Now is I do a group by on DOB I would get the data arranged accordingly 现在我在DOB上进行分组,我将得到相应安排的数据

select fname,lastname,dob,addr,sex,ssn from data group by dob(..rest of the columns..) having count(dob) > 1

But what I would like to know is, is it possible to get a group at a time, ie 但我想知道的是,是否可以一次组队,即

 1. Sanal    Pillai    12/11/85   Pune   M     -
 2. Anju     Pillai    12/11/85   Pune   F     345679

and then the rest two rows 然后其余两行

Hi i think you may not know the exact functionality of group by clause. 嗨,我认为您可能不知道group by子句的确切功能。 Below i have posted few lines for your understanding. 我在下面张贴了几行供您理解。

The Oracle GROUP BY clause is used in a SELECT statement to collect data across multiple records and group the results by one or more columns. Oracle GROUP BY子句在SELECT语句中使用,以收集多条记录中的数据并将结果按一个或多个列分组。

Syntax: 句法:

SELECT col1, col2, ... coln, 
       aggregate_function (column_name)
FROM tables
WHERE conditions
GROUP BY col1, col2, ... coln;

The column_names what and all you mentioned in select clause you should also mention in after group by keyword. column_names在select子句中提到的内容以及您在group by关键字之后还要提及的所有内容。 As per above syntax and your Question The required output query is: 根据上述语法和您的Question所需的输出查询为:

select fname,lastname,dob,addr,sex,sum(ssn) as ssn from data group by fname,lastname,dob,addr,sex  having count(dob) > 1

For More http://www.dba-oracle.com/t_oracle_group_by_having.htm 更多信息http://www.dba-oracle.com/t_oracle_group_by_having.htm

This is not possible. 这是不可能的。 Sql is used to get data from a database which sometimes has a specific order. Sql用于从有时具有特定顺序的数据库中获取数据。 Further analysis of the received data is done in the tool you use to show the data. 您可以使用显示数据的工具对接收到的数据进行进一步的分析。 This can be a programming language or another tool that can use sql to receive data. 这可以是一种编程语言,也可以是其他可以使用sql接收数据的工具。

You can use the RANK or DENSE_RANK analytic functions to assign grouping ID's and order by that: 您可以使用RANKDENSE_RANK分析函数通过以下方式分配分组ID和顺序:

with t1 as (
  select data.*, dense_rank() over (order by dob) grp from data
)
select t1.* from t1 order by grp;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM