A. Rehman Javed
A. Rehman Javed

Reputation: 309

how to retrieve last Week, previous month records from mysql table

I have a table which is shown in picture

mySql Table

I want to retrieve this information.

1) From this date(whatever it is) previous month total 'page_views' of all ip's

2) Today's 'page_views' grouped by 'page' (expample: id=7 have page =index.php having page_views =12 But in the same date id=13 have same page = index.php and page_views = 1) So they must show page_view of index.php = 13

Upvotes: 0

Views: 2153

Answers (2)

user1259132
user1259132

Reputation: 440

Use the below query to get the date one month before the specific date.

select date_sub(current_date, INTERVAL 1 MONTH) .

Upvotes: 1

Zane Bien
Zane Bien

Reputation: 23125

  • 1)

    SELECT SUM(page_views)
    FROM tbl
    WHERE date >= NOW() - INTERVAL 1 MONTH
    
  • 2)

    SELECT page, SUM(page_views)
    FROM tbl
    WHERE LEFT(date, 10) = CURDATE()
    GROUP BY page
    

Upvotes: 0

Related Questions