#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    18
    Rep Power
    0

    Sql query problem


    Hi,

    I have the following query:

    select * from thegroup_pageviews
    where date >= '2012-12-02'
    and date <= '2012-12-03'


    This query brings back following sample data from the table (first row is header info):

    title - views - date
    Home1 - 4 - 2012-12-02
    About Us - 3 - 2012-12-03
    Contact - 2 - 2012-12-02
    Reports - 5 - 2012-12-03
    About Us- 6 - 2012-12-02
    Home1- 7 - 2012-12-03
    Contact- 3- 2012-12-03

    Is there a way to write a query using specific date range that groups by the title? So for example if I would get distinct title with the sum of views for date range specified? So the query would then bring back following data for same date range as above

    title - views
    Home1 - 11
    About Us - 9
    Contact - 5
    Reports - 5

    Any help would be appreciated.

    Thanks
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    Originally Posted by zubair_h
    Is there a way to write a query using specific date range that groups by the title? So for example if I would get distinct title with the sum of views for date range specified?
    Um, all you have to do is translate your question into an SQL query:
    Code:
    SELECT
    	`title`
    	, SUM(`views`)
    FROM
    	`thegroup_pageviews`
    WHERE
    	`date` BETWEEN '2012-12-02' AND '2012-12-03'
    GROUP BY
    	`title`
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    18
    Rep Power
    0
    oh thanks! I'm not too familiar with sql yet. Looks simple enough!

IMN logo majestic logo threadwatch logo seochat tools logo