need help with postgres:)

Discussion in 'Databases' started by clinton, Oct 9, 2007.

  1. #1
    Hi, I just need to know how to add a number from each row of the whole table

    for example

    hit | date | visitis
    ------------------------
    1 | october | 4
    2 | october | 1
    3 | october | 8
    4 | october | 14
    5 | october | 7
    6 | october | 1
    7 | october | 2
    ------------------------

    thats 37 visits for all the hits

    I need to know how to make a query or php script that will ad those rows visits up so I know how many total visits my site is getting since I already know the hits.

    if anyone can help
    thank you
     
    clinton, Oct 9, 2007 IP
  2. benajnim

    benajnim Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Would something like this be what you're trying to get:

    select sum(visits) from whole_table where date = 'october'

    You could write it in another way so the single query would print each available month, and the total of hits for that month (select distinct date, sum(visits) from whole_table group by date). You could break it down by day, day of week, week of year, month, year... However!

    You could write the output from that query into another table, which would look roughly like this:

    insert into stats_table (date_period, hits) select date, sum(visits) from whole_table where date = 'october'

    This could be scripted to view the output from one of these queries in the browser if you're interested in having something like a "reporting site".

    I've done this kind of work extensively, so feel free to hire me if you want and I will craft a tool that will allow you to find strategic insights from your traffic logs!
     
    benajnim, Oct 17, 2007 IP