We help IT Professionals succeed at work.
Get Started

CTE or Partition on group by ?

149 Views
Last Modified: 2020-01-12
Hi

I have the following query

SELECT
      Count(DeviceId) as DeviceCount
      ,b.RootResellerId
      
  FROM Anayltics_Billing_DevicesReporting  b
  where DeviceId not in (863286020087590,869606020199992,869606020199993)
	and ReadingDate between '2020-01-10'  and '2020-01-31'
	Group by 	b.RootResellerId 

	order by DeviceCount desc

Open in new window



this outputs results like this:
DeviceCount	RootResellerId
3673	3071
2303	3449
1533	2990
1153	2975
1068	2299

Open in new window



I know need to do a join on
tblReseller.ResellerId = b.RootResellerId
to display tblReseller.ResellerName
This will enable me to see the reseller name on each row

However the inner join fails, i've read i may need to use CTE or partition but not sure how you add this to the end of the query.

sql server 2017
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE