Results 1 to 10 of 10

Thread: Sql query

  1. #1
    Join Date
    Nov 2012
    Posts
    6

    Sql query

    Hi
    Could somebody help me with my sql query. Namely my table look as follow
    dateline postid postwiews
    122233 1 22
    112333 2 43
    122222 3 12
    .....

    I have a more record there by it don't matter now. What is confusing me is dateline. How can I construct a sql query to return the max number of postviews and average postviews for a particular date?
    I know how to count all postviews in a table, but i have no idea how to count max postviews for specific date range for example post id:1 have the same date and how to return the max for this date.
    Could somebody provide me some example???
    Thanks in advance

  2. #2
    Join Date
    Mar 2004
    Posts
    480

  3. #3
    Join Date
    Nov 2012
    Posts
    6
    Thanks for the reply
    I am nearly find how to do my query but could somebody tell me how to sum the whole output from this query:

    SELECT Sum(threadviews) as Total,
    Max(threadviews) as Maximum
    FROM
    forum
    WHERE dateline >= UNIX_TIMESTAMP('2012-09-18')
    AND dateline < UNIX_TIMESTAMP('2012-11-18')
    Group by dateline

    it print me this table:

    Total Maximum
    11 11
    10 3
    17 13
    12 6
    0 0
    0 0
    11 9
    3 2
    3 2
    2 2
    0 0
    1 1

    Could somebody tell me how to sum the values from columns???
    Thanks in advance

  4. #4
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    860
    You should have a look at using AVG and MAX functions in a SELECT ... GROUP BY. In your case you need to group by the date.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com

  5. #5
    Join Date
    Nov 2012
    Posts
    6
    Hi
    What do you mean by avg and max in select? and the data is grouped by date(dateline). I am quite new so could I get some more information
    Thanks

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    12,568

  7. #7
    Join Date
    Nov 2012
    Posts
    6
    Ok i am loking for all the links but actually I can figered out how ot get the Total and miniumum but the max is not in the same range as max so could somebody make a suggestion where to include max for the sql above
    Thanks

  8. #8
    Join Date
    Nov 2012
    Posts
    6
    Hi
    Any ideas how can i get the sum for this sql query:
    SELECT Sum(threadviews) as Total,
    Max(threadviews) as Maximum
    FROM
    forum
    WHERE dateline >= UNIX_TIMESTAMP('2012-09-18')
    AND dateline < UNIX_TIMESTAMP('2012-11-18')
    Group by dateline

    is returning the result but I don's know how to get the sum I will be appreciate for help
    Thanks

  9. #9
    Join Date
    Oct 2009
    Location
    221B Baker St.
    Posts
    486
    Suggest you post what you Are getting and what you want for a result.

    Data examples are most helpful.

  10. #10
    Join Date
    Nov 2012
    Posts
    6
    Hi
    there is my sql:
    SELECT Sum(threadviews) as Total,
    Max(threadviews) as Maximum
    FROM
    forum
    WHERE dateline >= UNIX_TIMESTAMP('2012-09-18')
    AND dateline < UNIX_TIMESTAMP('2012-11-18')
    Group by dateline

    it print me this table:

    Total Maximum
    11 11
    10 3
    17 13
    12 6
    0 0
    0 0
    11 9
    3 2
    3 2
    2 2
    0 0
    1 1
    But I would like to sum row, could somebody help me with this
    Thanks

Posting Permissions

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