SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard westmich's Avatar
    Join Date
    Mar 2000
    Location
    Muskegon, MI
    Posts
    2,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Calculating a percentage

    Is it possible to calculate a percentage within a query?

    Normally, I would handle this by running a query and than do server-side calcualtions based on the results diveded by the total number of records returned.
    Code:
    Select Count(Employee) as Total, Department
    From Employees
    Group By Department
    Order By Department
    Westmich
    Smart Web Solutions for Smart Clients
    http://www.mindscapecreative.com

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    What would have to be in percentages? We need some more info on your database columns/datatypes/structure. Otherwise it's just simple arithmetic nested in your query that would get a percentage.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by westmich
    Is it possible to calculate a percentage within a query?
    yes
    Code:
    select count(Employee)          as Total
         , count(Employee) * 100
          / ( select count(Employee)
                from Employees )    as DeptPercent
         , Department
      from Employees
    group 
        by Department
    order 
        by Department
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Wizard westmich's Avatar
    Join Date
    Mar 2000
    Location
    Muskegon, MI
    Posts
    2,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome
    Westmich
    Smart Web Solutions for Smart Clients
    http://www.mindscapecreative.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •