Count Function

karinos57 used Ask the Experts™
on
Hi,
can someone explain to me this line of code with examples?  i am trying to understand it but lost in the syntax of Count function.  thanks for your help

Left(round((count(*) - sum(Errors) * 1.0) / count(*) * 100,2),6) as Availability
Comment
Watch Question

Do more with

EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
break it down one set of parens at a time:

(count(*) - sum(Errors) * 1.0)  -- the number of matching rows, minus the sum of the Errors column.  Multiply by 1.0 to convert it from INT to FLOAT

/ count(*) * 100,2)  -- divide that result by 100 times the number of rows (e.g. count(*))

(round ... ,2)  -- round this to two decimal places

Left( ... ,6 )  -- take the six left-most characters

Commented:
so, if the result of the math is 1003.14159, then rounding it to two decimals would yield 1003.14, and taking the 6 left-most characters would be '1003.1'
Commented:
count(*) refers to the number of matching rows in a query, or in a group (in case a GROUP BY clause is used)

select myColumn, count(*) as matches
group by myColumn

The above would show the number of matching rows for each unique instance of myColumn (e.g. the values within myColumn)

Commented:
wow! very detailed answer, i really appreciate that.  thanks.  i would like to ask you another question since you know very well sql. i am not sure if i need to post another question so you can help me..

Commented:
If it is simple I will try. :)  If it is complex you may want to post it as another question so that others can help too.

Commented:
thnx

Do more with

Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.