473,473 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Top 25 Plans By Territory

2 New Member
Greetings,
I have a query built that aggregates National plan names to a territory #. The columns/fields are as follows. Terr #, Plan Name, Total Units. It is already sorted by Terr # Ascending and Total Units Descending.

All I need to do is return the Top 5 Plans per Terr # based on the Total Units.

Can anyone help????
Oct 23 '07 #1
3 1046
Rabbit
12,516 Recognized Expert Moderator MVP
Greetings,
I have a query built that aggregates National plan names to a territory #. The columns/fields are as follows. Terr #, Plan Name, Total Units. It is already sorted by Terr # Ascending and Total Units Descending.

All I need to do is return the Top 5 Plans per Terr # based on the Total Units.

Can anyone help????
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM Query1 AS x
  3. WHERE [Plan Name] IN (SELECT TOP 5 [Plan Name] FROM Query1 WHERE [Terr #] = x.[Terr #] ORDER BY [Total Units] DESC;);
  4.  
Oct 23 '07 #2
cmcpherson007
2 New Member
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM Query1 AS x
  3. WHERE [Plan Name] IN (SELECT TOP 5 [Plan Name] FROM Query1 WHERE [Terr #] = x.[Terr #] ORDER BY [Total Units] DESC;);
  4.  

Rabbit-


This was exactly what I needed. Thanks for your help on this one!
Oct 24 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Rabbit-


This was exactly what I needed. Thanks for your help on this one!
No problem.
Oct 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Thomas R. Hummel | last post by:
I have a stored procedure that suddenly started performing horribly. The query plan didn't look right to me, so I copy/pasted the code and ran it (it's a single SELECT statement). That ran pretty...
3
by: James Walker | last post by:
Hi there - hoping someone can help me here! I have a database that has been underperforming on a number of queries recently - in a test environment they take only a few seconds, but on the live...
6
by: Christine Wolak | last post by:
I'm looking for assistance on a problem with SQL Server. We have a database where a particular query returns about 3000 rows. This query takes about 2 minutes on most machines, which is fine in...
0
by: Larry Maturo | last post by:
I noticed that in SQL Server Management Studio, under Management, there is a Legacy folder with maintenace plans created by adding entries to the system tables dbo.sysmaintplan_* tables (i.e. all...
1
by: Dale Franklin | last post by:
This should be a rather ROUTINE procedure for you DBAs. I keep hearing at technical conferences and user groups the phrase "then rebind all your plans and packages" (after reorg, load, &...
5
by: sql-db2-dba | last post by:
We have DB2 UDB v8.1 fixpak3 on AIX 5. Production and Development configuarations (at least for DB2) are identical albeit production is a 2-way server while development has only one processor....
5
by: sqlgirl | last post by:
Hi, We are trying to solve a real puzzle. We have a stored procedure that exhibits *drastically* different execution times depending on how its executed. When run from QA, it can take as...
1
by: KIMU | last post by:
hi dudes , i want to insert data in tables that is in english, i am from india. for that i want to create database ,for that i need these values, i am using xp sp2 CODE SET ...
4
by: beckycarter04 | last post by:
I have built a form database and it is linked to a phone caller ID system. I need a validation IF code that is "if the caller id prefix starts with a 613476 than it screen pops a "Quinte territory"...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.