troubleshooting Question

rank over query

Avatar of jamesmetcalf74
jamesmetcalf74Flag for United States of America asked on
Microsoft SQL Server
4 Comments2 Solutions63 ViewsLast Modified:
trying to use rank over partition with a join and am failing.  the following query works but when i try to only select the rows where the rank is 1, it doesnt recognize dog as a column

the working querry
select RANK () OVER (PARTITION BY B.ACCOUNTKEY ORDER BY B.ADDDTTM DESC) AS DOG ,* from billing.account A
INNER JOIN BILLING.BILL B
ON A.ACCOUNTKEY = B.ACCOUNTKEY

the query that doesnt work and returns dog as an unrecognized column
select RANK () OVER (PARTITION BY B.ACCOUNTKEY ORDER BY B.ADDDTTM DESC) AS DOG ,* from billing.account A
INNER JOIN BILLING.BILL B
ON A.ACCOUNTKEY = B.ACCOUNTKEY
 where DOG = 1

the error is "invalid column name 'DOG'
can someone help
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros