|
-
Jul 14th, 2003, 08:15 AM
#1
Thread Starter
Hyperactive Member
How to get the 20 MOST and LEAST profitable customers from an OLEdb into Listboxes 1
Gentlemen:
Could you please let me know the right code for extracting the 20 top most and 20 least profitable customers using the SALES column in Database1 into listbox1 and 2?
On listbox1 I need to show:
20 MOST PROFITABLE CUSTOMERS
TotalAmount / CustomerName / CustomerCity
On listbox2 I need to show:
20 LEAST PROFITABLE CUSTOMERS
TotalAmount / CustomerName / CustomerCity
Thanks
Andy
I’m using:
VB.NET 2003 Standard
Access 2000
-
Jul 14th, 2003, 09:12 AM
#2
Frenzied Member
Select Top 20 TotalAmount,CustomerName,CustomerCity from mytable Order By TotalAmount Desc
That will give you the top 20 who have highest total amount.
And the following:
Select Top 20 TotalAmount,CustomerName,CustomerCity from mytable Order By TotalAmount ASC
should give you the least.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jul 14th, 2003, 09:19 AM
#3
Thread Starter
Hyperactive Member
Lunatic3:
Thank you for you reply:
Question:
Do you think this query will add all the values of all the sales corresponding to a specific customer?
What I mean is most customers have many sales, would the query first Sum all sales for each customer and then select the top 20?
Andy
-
Jul 14th, 2003, 09:22 AM
#4
Frenzied Member
No, that query does not do it. You should modify it in a way that first sums up the amount (using sum function and grouping) then get the top and least 20 of those sums.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jul 14th, 2003, 09:25 AM
#5
Thread Starter
Hyperactive Member
Lunatic3:
Could you give me an idea?
Pease!!!
-
Jul 14th, 2003, 09:34 AM
#6
Frenzied Member
SELECT DISTINCTROW TOP 20 Sum(TotalAmount) AS [Sum Of Total Amount],CustomerName,CustomerCity FROM mytable
GROUP BY CustomerName ORDER BY Sum(TotalAmount) DESC
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jul 14th, 2003, 09:40 AM
#7
Thread Starter
Hyperactive Member
Lunatic3:
Thank you very much, I'll give it a try!!
-
Jul 14th, 2003, 09:55 AM
#8
Thread Starter
Hyperactive Member
Lunatic3:
I forgot to ask you how would you put the result of this query into the two listboxes?
I only need these fields in the listboxes:
TotalAmount / CustomerName / CustomerCity
Thanks
-
Jul 14th, 2003, 11:15 AM
#9
Frenzied Member
I am afriad you can not show three fields in the listbox unless you use custom listboxes available. And for one field you may use that query to buld an adapter, then fill a dataset with that adapter and set the datasource, datamember and other related properties of the listbox based on the table in the dataset.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|