If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Sql query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Mar 2004
Posts: 480
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #6 (permalink)  
Old
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 11,662
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #7 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #8 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #9 (permalink)  
Old
Registered User
 
Join Date: Oct 2009
Location: 221B Baker St.
Posts: 487
Suggest you post what you Are getting and what you want for a result.

Data examples are most helpful.
Reply With Quote
  #10 (permalink)  
Old
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On