[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Query addition

Posted on 2013-01-12
4
Medium Priority
?
160 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:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

656 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