Can anyone help me with SQL that will return highest count for App_ID. I’m running this SQL which returns following data set.
SELECT COMP_ID, APP_ID, count(*) as cnt
FROM APP_ACCT_VIEW
GROUP BY COMP_ID, APP_ID
COMP_ID APP_ID CNT
cpo1000c AT 999
cpo1kact AT 895
cpo1kact CPOPYMTS_Administrative 1020
cpo1000c CPOPYMTS_HighValue 1900
cpo1kact CPOPYMTS_HighValue 1020
cpo1000c CPOPYMTS_Internal 1999
cpo1kact CPOPYMTS_Internal 1020
cpo1kact IRCDR 1020
cpo1000c IRCDR 50
But I need SQL to return the top/highest cnt for each APP_ID and need output to look like this.
COMP_ID APP_ID CNT
cpo1000c AT 999
cpo1kact CPOPYMTS_Administrative 1020
cpo1000c CPOPYMTS_HighValue 1900
cpo1000c CPOPYMTS_Internal 1999
cpo1kact IRCDR 1020
Thanks
Dipen
In most databases, you can use the
row_number()function to do this:If this is not available, you have to do the calculation of seqnum some other way, such as a correlated subquery.