Oracle - 计算列的不同值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3005981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:47:06  来源:igfitidea点击:

Oracle - Count distinct values of a column

oraclecount

提问by Luciana Borela

I have this table:

我有这张表:

Reason|Area_Code|Id
x         dig     1
x         dig     2
y         dig     3
h         util    4
x         dig     5

I'm trying for a SQL that returns:

我正在尝试一个返回的 SQL:

Reason|Amount of distinct Reason|Area_code
x              3                  dig
y              1                  dig
h              1                  util

I will use this result to plot a chart. I don′t have any idea on how this SQL can be done. Could you help me?

我将使用此结果绘制图表。我不知道如何完成此 SQL。你可以帮帮我吗?

回答by Charles Bretana

Try This:

尝试这个:

  Select Reason, Count(*) AmountOfReason, Area_Code
  From Table
  Group By Reason, Area_Code

... but this assumes that Area_Code is always determined by Reason, i.e., they are always paired, that you do not have 2 rows in yr table like

...但这假设 Area_Code 始终由 Reason 确定,即,它们始终成对,您在 yr 表中没有 2 行,例如

x   util   5
x    dig   6

cause if that was the case this won't work.

因为如果是这样的话,这将不起作用。