SQL Guru needed

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

SQL Guru needed

Post by GeXus »

I'm attempting to build reports on data that I have.. The data is for advertising cost and revenue, here's a basic break down

Table: Clicks
id
campaign_id
cpc
date

Table: Sales
click_id
earned
click_date

I just want a query that returns the total cost (sum of cpc in clicks table) and total earned (sum of earned in sales table), then group it by each day. The problem I'm having is with summing the cpc in the clicks table, because when grouping by day it just returns one value, and doing a subquery doesn't seem to work.. so i'm not really sure...

If anyone is really good with SQL and thinks they'd have no problem doing this, please PM your rates, I have other queries along the similar lines as these.

OR if someone wants to post suggestions, thats fine too... Thanks!
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Re: SQL Guru needed

Post by bdlang »

GeXus wrote: I just want a query that returns the total cost (sum of cpc in clicks table) and total earned (sum of earned in sales table), then group it by each day. The problem I'm having is with summing the cpc in the clicks table, because when grouping by day it just returns one value...
Isn't that the point of performing the GROUP BY on the date column? To get one value per day? Or am I misreading your statement?

Did you ever solve this?
Post Reply