SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Calculating a percentage on two columns

    I have the following query that gives me a click percentage based on how many email alerts have been sent out and how many of those have been clicked on.

    PHP Code:
    select sIDkeywordclickedalertsclicked/alerts*100 as percent from searches where clicked alerts and clicked 0
    I tried adding the following to the WHERE clause, but the query failed:

    PHP Code:
    where percent 33.33 
    What is the best way to add that I only want to see results where the percentage is less than 33.33 ?

    Thanks!
    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Code:
     
    SELECT sID
         , keyword
         , clicked
         , alerts
         , 100.0*clicked/alerts AS percent 
      FROM searches 
     WHERE clicked > 0
       AND 100.0*clicked/alerts < 33.33
    note i remove clicked < alerts because that's implied by the 33% condition
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks brother, works like a charm.
    Convert your dollars into silver coins. www.convert2silver.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
  •