Solved

Query addition

Posted on 2013-01-12
4
157 Views
Last Modified: 2013-01-17
Hi,

I use the following query to count unique pageviews, grouped by date.

$sqlStr = '
SELECT
	date(viewdate) AS myDate,
	COUNT(DISTINCT userip) AS myCount
FROM
	archive_views
GROUP BY
	myDate
ORDER BY
	myDate DESC;
';

Open in new window


I need to add this part to it, but not sure how.

SUM(earnings) AS mySum WHERE approved='true' DISTINCT userip

Open in new window


The idea is to count all approved earnings from a specific date, but only from unique visitors (my affiliates only get paid per 24 hour unique visitor).
0
Comment
Question by:kgp43
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 27

Accepted Solution

by:
yodercm earned 500 total points
ID: 38770585
Can you just use

SELECT
      date(viewdate) AS myDate,
      COUNT(DISTINCT userip) AS myCount
FROM
      archive_views
GROUP BY
      myDate, userip
ORDER BY
      myDate DESC;
';
0
 

Author Comment

by:kgp43
ID: 38770593
Update: let me test a bit and get back to you.

 - I do not need the approved='true'
0
 

Author Comment

by:kgp43
ID: 38770614
Does not work.

And "SUM(earnings) AS mySum," does not count earnings per unique 24 hour IP either... I think. Hmm, hard one.

<?php
$sqlStr = '
SELECT
	date(viewdate) AS myDate,
	SUM(earnings) AS mySum,
	COUNT(DISTINCT userip) AS myCount
FROM
	archive_views
GROUP BY
	myDate, userip
ORDER BY
	myDate DESC;
';

# Query
$view_query = mysql_query($sqlStr) or die(mysql_error());
while($view_fetch = mysql_fetch_array($view_query)) {	
	?>

	<tr>
		<td>Date: <?php echo date("F jS, Y", strtotime($view_fetch['myDate'])); ?></td>
		<td>Views: <?php echo $view_fetch['myCount'] ?></td>
		<td>Amount: <?php echo "$".round($view_fetch['mySum'], 2); ?></td>
	</tr>
	
<?php
}
?>

Open in new window

0
 

Author Comment

by:kgp43
ID: 38770644
I changed my script a bit, so I can just use this instead.

$sqlStr = '
SELECT
	date(viewdate) AS myDate,
	SUM(earnings) AS mySum,
	COUNT(DISTINCT userip) AS myCount
FROM
	archive_views
GROUP BY
	myDate
ORDER BY
	myDate DESC;
';

Open in new window


Going to close the question soon, unless something else comes up regarding this query.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question