
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
sum, aggr and count
Hi All,
I have the below expression in my qlikview script and would like to know how we can reproduce the same in SQL so that i can validate the numbers at the backend.
Sum(Aggr(Count( DISTINCT ProductCode), ProductCode, Division))
I understand that AGGR function will work like a group by function in SQL. The output of Aggr(Count( DISTINCT ProductCode), ProductCode, Division) will be the count of productcode grouped by productcode and Division.
Thank you.
Regards,
Viresh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May be this
SELECT SUM(COUNT) AS SUM
FROM (
SELECT Count(DISTINCT ProductCode) AS COUNT,
ProductCode,
Division
FROM ....
Group By ProductCode, Division);


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This expression does not make sense. The Count() will be one for every ProductCode/Division combination (and the DISTINCT will do nothing since you are already distinct because of the Aggr() dimensions). You cannot do this expression directly in SQL as SQL will not allow you to aggregate and group by the same field. The nearest I could get was
SELECT Count(*)
FROM ...
Group By ProductCode, Division;
