Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6837797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:31:12+00:00 2026-05-26T23:31:12+00:00

please take a look of this query: SELECT DATE(datetime), COUNT(1) as numVisits FROM .table_stats.

  • 0

please take a look of this query:

SELECT DATE(datetime), COUNT(1) as numVisits 
FROM ".table_stats." 
WHERE type='profile_visit' 
    AND user_url = '".$_GET['ref']."' 
    AND id_user='".$_SESSION['user_code']."' 
GROUP BY DATE(DATE_SUB(datetime, INTERVAL 1 DAY))

This query counts the number of times that type is equal to ‘profile_visit’ by each date, as a result it gives me two rows (DATE(datetime), numVisits). This is a screen capture of the table table_stats:
Table 1
Table_Stats


Ok, until now you can understand that every time a user comes to the site a new element is inserted on the table with type=profile_visit and the datetime field with the date and time of the visit, thats why i use a GROUP BY DATE(datetime) to count the total number of visits by day.

Here comes the complex part, when the type field is equal to ‘click’ and the origin is ‘imp’ that means that a user hits a particular button on the page, i will like to know how many times that button was clicked (no matter the ip) by day, just like i did with the profile visits.

I can make two querys, one to know the total visits (like the one before) and another similar just by grouping by datetime when type is ‘click’ and origin is ‘imp’.

The problem is that i will like to make this just in one call in order to count the total visits by date in the row NumVisits like i did before and a new row call NumClick with the total of clicks made. This is why i dont want more calculations on my php server, if its possible will be great to make all the calculation on the sql server.

So finally, if you call this query to the table:

SELECT DATE( DATETIME ) , COUNT( 1 ) AS numVisits
FROM stats_ram
WHERE TYPE =  'profile_visit'
AND user_url =  'xxx'
AND id_user =  '88e91'
GROUP BY DATE( DATE_SUB( DATETIME, INTERVAL 1 
DAY ) ) 
LIMIT 0 , 30

You will get:

DATE(datetime)  numVisits
2011-11-16      7

How can i add another row with the total type=click AND origin=imp made by DATE(datetime)???

Thanks for any help!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:31:12+00:00Added an answer on May 26, 2026 at 11:31 pm
    SELECT 
        DATE(DATETIME), 
        SUM(CASE WHEN type = 'profile_visit' THEN 1 ELSE 0 END) AS numVisits,
        SUM(CASE WHEN type = 'click' AND origin = 'imp' THEN 1 ELSE 0 END) numClicks
    FROM stats_ram
    WHERE user_url = 'xxx'
        AND id_user = '88e91'
    GROUP BY DATE(DATE_SUB(DATETIME, INTERVAL 1 DAY)) 
    LIMIT 0, 30
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before I ask my question, please take a look at this example function: DateTime.TryParse(01/01/2000,
Please can you take a look at this query and point out what I'm
Please take a look at this example: #include <iostream> #include <vector> #include <string> using
Please take a look at this code: template<class T> class A { class base
Please take a look at this piece of code. I'm allocating one byte for
Please take a look at this below line of code in JSF <h:inputText id=name
Please take a look at this macro. It is used in Symbian OS SDK,
Please take a look at THIS page. Please feed in some random data and
Please take a look at this line: ${server_username}:${server_password}@@{server}:/tmp The double @@ causes problems. Instead
Please take a look at this image: alt text http://a.imageshack.us/img21/6190/64635037.png I have a MDI

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.