Oracle11g 使用SQL Developer为每个唯一字段值选择单行

Oracle11g 使用SQL Developer为每个唯一字段值选择单行,oracle11g,oracle-sqldeveloper,Oracle11g,Oracle Sqldeveloper,我有数千行数据,其中一段看起来像: +-------------+-----------+-------+ | Customer ID | Company | Sales | +-------------+-----------+-------+ | 45678293 | Sears | 45 | | 01928573 | Walmart | 6 | | 29385068 | Fortinoes | 2 | |

我有数千行数据,其中一段看起来像:

+-------------+-----------+-------+  
| Customer ID |  Company  | Sales |  
+-------------+-----------+-------+  
|    45678293 | Sears     |    45 |  
|    01928573 | Walmart   |     6 |  
|    29385068 | Fortinoes |     2 |  
|    49582015 | Walmart   |     1 |  
|    49582015 | Joe's     |     1 |  
|    19285740 | Target    |    56 |  
|    39506783 | Target    |     4 |  
|    39506783 | H&M       |     4 |  
+-------------+-----------+-------+  
在每种情况下,如果客户ID出现不止一次,“Sales”中的值也相同,但“Company”中的值不同(在整个表中都是如此)。我需要“Customer ID”中的每个值只显示一次,因此我需要为每个Customer ID指定一行

换句话说,我希望上面的表格看起来像:

+-------------+-----------+-------+  
| Customer ID |  Company  | Sales |  
+-------------+-----------+-------+  
|    45678293 | Sears     |    45 |  
|    01928573 | Walmart   |     6 |  
|    29385068 | Fortinoes |     2 |  
|    49582015 | Walmart   |     1 |  
|    19285740 | Target    |    56 |  
|    39506783 | Target    |     4 |    
+-------------+-----------+-------+
如果有人知道我该怎么做,我会非常感谢你的帮助。
谢谢

如果您已经使用sql生成了这些数据,那么这会很有帮助

但它可能是这样的

SELECT customer_id, Max(Company) as company, Count(sales.*) From Customers <your joins and where clause> GROUP BY customer_id
选择客户标识,最大(公司)为公司,按客户标识从客户组中统计(销售。*)
假定;有很多公司,他们会从不同的表格中挑选出最多的发生次数和销售数据


希望这能有所帮助。

按客户分组\u ID
?@Marc B-我不知道如何使用分组方式,我不想聚合任何字段。因此,您希望选择哪家公司,例如按字母顺序排列?您可以不使用聚合进行分组,只需获得一个按字段分组,而不是所有字段。@TonyHopkinson-出于我的目的,我选择哪家公司并不重要。只要只有一个。我在下面选择了一个适合我的解决方案。