Count Function

karinos57 used Ask the Experts™
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
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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
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'
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)
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.


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..
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.



Do more with

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

Start 7-Day Free Trial