Teradata OLAP Functions

Database

Teradata OLAP Functions

Need help with a query using Teradata Olap funciton.  My data looks like this

COUNT GLAccount ProductID
1 132230 100118
2 132230 100120
1 132240 100035
1 132240 100036
2 132511 100148
2 132511 100149
1 152501 100263

Desired Output

(First)  Pick Up Product for a GLAccount where Count is Greatest

(Second)  If count for 2 products for the same GLAccount are the Same,  Pick the 1st Occurance.  (Assume Data is Sorted by GLAccount, Product)

COUNT GLAccount ProductID
2 132230 100120
1 132240 100035
2 132511 100148
1 152501 100263
1 REPLY
N/A

Re: Teradata OLAP Functions

QUALIFY
ROW_NUMBER()
OVER (PARTITION BY GLAccount
ORDER BY COUNT DESC, Product) = 1

Assuming that COUNT is the result of a aggregation you can simply replace COUNT with the actual function, e.g. COUNT(*)