MS SQL 2005, minimizing of count.

I have some numbers from a table like this:
Number1   Number2    Number3    Number4
01                 02                03              04
And I also have a list of number as a result:
ResultNumber
01
01
02
03
05
07
04

So if I make a count statement of the numbers from the result I will have:
count(01) = 2, count(02) = 1, count(03) = 1, count(04) = 1. --> min(count) = 1
And here is my problem: I want to calculate this value:  (01*02*03*04)*min(count)

How can I get that result from select statement?
JameMeckAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cyberkiwiCommented:
Hi,

I am not clear about the relationship between your two tables, but generally you can do as follows
declare @myTable table (ResultNumber varchar(3))
insert @myTable values ('01')
insert @myTable values ('01')
insert @myTable values ('02')
insert @myTable values ('03')
insert @myTable values ('05')
insert @myTable values ('07')
insert @myTable values ('04')

Select Min(SingleCount) From
(
Select ResultNumber, SingleCount=count(*) from @myTable
Group by ResultNumber
) InnerSelect

Open in new window

cyberkiwiCommented:
I am sure this is completely the wrong track, but hopefully it will lead you in the right path.
declare @myNumbers table (Number1 int, Number2 int, Number3 int, Number4 int)
insert @myNumbers values (1,2,3,4)
declare @myTable table (ResultNumber int)
insert @myTable values ('01')
insert @myTable values ('01')
insert @myTable values ('02')
insert @myTable values ('03')
insert @myTable values ('05')
insert @myTable values ('07')
insert @myTable values ('04')

--(01*02*03*04)*min(count)
Select (Number1 * Number2 * Number3 * Number4) * MinFromCounts FROM
(
	Select MinFromCounts = Min(SingleCount) From
	(
		Select ResultNumber, SingleCount=count(*) from @myTable
		Group by ResultNumber
	) InnerSelect
) InnerSelect2
CROSS JOIN @myNumbers N

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JameMeckAuthor Commented:
Thanks! It is perfect solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.