How to add a sequential row number column to an aggregate view.

I have a query  that agrregates the values from a table in oracle. I want to add a column with sequential rownumbers and I get the following error:

"Ora-00979 Not a valid Group by expression."

It is trying to pull the row numbers from the source data. What  I want is to have a squential id number colum.

SELECT ROWNUM,
         COUNT (DISTINCT COVERPAGE_GIS.PARENT_COMPANY) COMPANIES,
         FORM477_PART_VI_GIS.TRACT_FIPS
    FROM COVERPAGE_GIS, FORM477_PART_VI_GIS
   WHERE (COVERPAGE_GIS.CONTROL_ID = FORM477_PART_VI_GIS.CONTROL_ID)
         AND ( (FORM477_PART_VI_GIS.UPLOAD_RATE_CODE >= 2)
              OR (FORM477_PART_VI_GIS.DOWNLOAD_RATE_CODE >= 2))
GROUP BY FORM477_PART_VI_GIS.TRACT_FIPS
OR1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
Try this:
SELECT ROWNUM,
         COUNT (DISTINCT COVERPAGE_GIS.PARENT_COMPANY) OVER ( partition by  FORM477_PART_VI_GIS.TRACT_FIPS) COMPANIES,
         FORM477_PART_VI_GIS.TRACT_FIPS
    FROM COVERPAGE_GIS, FORM477_PART_VI_GIS
   WHERE (COVERPAGE_GIS.CONTROL_ID = FORM477_PART_VI_GIS.CONTROL_ID)
         AND ( (FORM477_PART_VI_GIS.UPLOAD_RATE_CODE >= 2)
              OR (FORM477_PART_VI_GIS.DOWNLOAD_RATE_CODE >= 2))

Open in new window

0
k_murli_krishnaCommented:
SELECT ROWNUM, COMPANIES, TRACT_FIPS
FROM(SELECT
         COUNT (DISTINCT COVERPAGE_GIS.PARENT_COMPANY) COMPANIES,
         FORM477_PART_VI_GIS.TRACT_FIPS
    FROM COVERPAGE_GIS, FORM477_PART_VI_GIS
   WHERE (COVERPAGE_GIS.CONTROL_ID = FORM477_PART_VI_GIS.CONTROL_ID)
         AND ( (FORM477_PART_VI_GIS.UPLOAD_RATE_CODE >= 2)
              OR (FORM477_PART_VI_GIS.DOWNLOAD_RATE_CODE >= 2))
GROUP BY FORM477_PART_VI_GIS.TRACT_FIPS)iq;

You can remove iq if there is a problem or use with AS iq. Not to sure about this.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OR1Author Commented:
Your solution works with or without the iq. Can you tell me the reason for it?

Thanks
0
k_murli_krishnaCommented:
In Oracle iq is optional. In DB2, iq or AS iq is compulsory for nested query (overall/select list/where/having) i.e. normal OR correlated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.