Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2012
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Get percentages in query

    Ok I have a single table called opportunities, within that table I have field called sales_stage. I need to get the percentage of rows where sales_stage is "Closed Won" and also get percentage of rows where sales_stage is "Closed Lost" And basically just display the two headings Closed won and Closed Lost.

    I'm a little bit lost with how to do this one, here is an sql fiddle

    http://sqlfiddle.com/#!2/ac28d/13

  • #2
    New Coder
    Join Date
    Apr 2012
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This is what I was looking for.

    SELECT
    sum(sales_stage="Closed Won")/count(*) * 100 AS won_pct,
    sum(sales_stage="Closed Lost")/count(*) * 100 AS lost_pct
    FROM opportunities


  •  

    Posting Permissions

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