[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Query addition

Posted on 2013-01-12
4
Medium Priority
?
161 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
  • 3
4 Comments
 
LVL 27

Accepted Solution

by:
Cornelia Yoder earned 1500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month19 days, 1 hour left to enroll

834 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