Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Information on how to write a query

Author  Topic 

cludwig
Starting Member

3 Posts

Posted - 2003-04-21 : 16:07:10
I have to find out how many of our customers fall within a range of average $s.

I'm not sure how to begin.

I have a field "average" in the account master table that states each customers "average order".

I need a count of customers that fit in the following average ranges:
0-9.99
10-19.99
20 - 49.99
50 - 99.99
100 - 499.99
500 - 999.99
1000 - 4999.99
5000 and over

I hope this gives you enough information

X002548
Not Just a Number

15586 Posts

Posted - 2003-04-21 : 16:31:31
I'm thinking:

SELECT ' 0.00 to 9.99' As Range, COUNT(*) Num_Customers FROM Table WHERE AVG_AMT BETWEEN 0 AND 9.99 UNION ALL
SELECT ' 10.00 to 19.99' As Range, COUNT(*) Num_Customers FROM Table WHERE AVG_AMT BETWEEN 10 AND 19.99 UNION ALL
SELECT ' 20.00 to 49.99' As Range, COUNT(*) Num_Customers FROM Table WHERE AVG_AMT BETWEEN 20 AND 49.99 UNION ALL
SELECT ' 50.00 to 99.99' As Range, COUNT(*) Num_Customers FROM Table WHERE AVG_AMT BETWEEN 50 AND 99.99 UNION ALL
SELECT ' 100.00 to 499.99' As Range, COUNT(*) Num_Customers FROM Table WHERE AVG_AMT BETWEEN 100 AND 499.99 UNION ALL
SELECT ' 500.00 to 999.99' As Range, COUNT(*) Num_Customers FROM Table WHERE AVG_AMT BETWEEN 500 AND 999.99 UNION ALL
SELECT ' 1000.00 to 4999.99' As Range, COUNT(*) Num_Customers FROM Table WHERE AVG_AMT BETWEEN 1000 AND 4999.99 UNION ALL
SELECT 'OVER 5000.00' As Range, COUNT(*) Num_Customers FROM Table WHERE AVG_AMT > 5000





Brett

8-)
Go to Top of Page

cludwig
Starting Member

3 Posts

Posted - 2003-04-21 : 16:39:11
Thanks... I'll give it a try.

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-04-21 : 18:13:29
Put the values into a table avgtamnts (lamnt, hamnt) and

select lamnt, hamnt, sum(case when AVG_AMT between lamnt and hamnt then 1 else 0 end
from tbl, avgtamnts
group by lamnt, hamnt

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

cludwig
Starting Member

3 Posts

Posted - 2003-04-22 : 09:16:53
Thanks... I appreciate the help. This looks good.

Go to Top of Page
   

- Advertisement -