SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Counter from column data with blank spots

    I have marked a column "index" in a table "count" every time I visit the website with a "1".

    I would like the SQL statement that would add up all the "1"s and give the site counter a value.

    There are some blank spaces where other websites with different columns in table "count" were recorded.

    I tried:

    "SELECT SUM(index) FROM count;"

    but this yielded the blank cell.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    That query should give two errors, because index and count are reserved words. Enclose them in backticks, or even better, give table and column another name.
    And when you say "blank spaces" that worries me, isn't the "count" column numerical?

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Enclose them in backticks...
    only if OP is using mysql

    OP didn't say which database system, though
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •