# Informatica中实现count(distinct)

Thanks for your response. Here is the sample data information:

A id1 $200 A id1$300
A id2 $150 B id3$100
B id4 $20 I want the following in the output: Name distinct-Count Totalamt A 2$650

B 2 \$120

One way to do this is to use 2 aggregators. The First aggregator group and sum amt by Name and ID.
On the second aggregator group by Name and count id and sum amt.

So if I remove the duplicate row in the Sorter I will get incorrect distinct-count and totalamt for "A".

There are two different ways.

1) Suggested by Manas - to use two aggregates.
2)Flaging the record as 1 and 0 before aggregate. For this, you should have sorted data on name and id.
If you have sorted data coming from source, try 2nd option as given below.
In expression transformation before aggregator.

IN_ID
v_ID_CNT = IIF(ISNULL(v_ID) Or IN_ID!= V_ID,1, 0)
O_ID_CNT=V_ID_CNT
V_ID=IN_ID

O_ID_CNT will go in to your aggregator.

You need to create one more port in aggregator for SUM(O_ID_CNT) which will return the distinct count of IDs.
(No change in GROUP BY columns)

#### informatica 学习日记整理

2015-03-07 22:43:36

#### INFORMATICA 函数整理

2016-08-09 16:57:15

#### count distinct是如何实现的

2017-10-27 12:09:21

#### informatica 基本组件使用说明

2016-01-05 11:53:33

#### Informatica 初学日记全（转载）

2016-09-23 16:18:34

#### 记录一下= =

2017-03-11 08:31:30

2015-11-20 16:17:57

#### C语言开发流程

2016-11-06 14:38:05

#### ORACLE集合操作符号UNION、UNION ALL、INTERSECT、MINUS来进行查询结果的合并操作

2012-08-27 16:41:01

#### 大数据

2017-02-25 11:07:12