[snip]
Here is a paired down version of a query I want to make. How can I get
the
"grandtotal" column? I know about the "HAVING" clause, but that's only
going
to be good for weeding out rows I don't want. I just want to do some
basic
math here.
SELECT a.*,
DATE_FORMAT(a.created_on,'%m/%d/%y %h:%i:%s %p') AS
created_on_format,
DATE_FORMAT(a.timestamp,'%m/%d/%y %h:%i:%s %p') AS
timestamp_format,
(views * ppview) AS totalviews,
(clicks * ppclick) AS totalclicks,
totalviews + totalclicks AS grandtotal
FROM advertisements a;
There has got to be a better way than this (which would be a colossal
waste
of computing power to recalculate something that was just done!):
SELECT a.*,
DATE_FORMAT(a.created_on,'%m/%d/%y %h:%i:%s %p') AS
created_on_format,
DATE_FORMAT(a.timestamp,'%m/%d/%y %h:%i:%s %p') AS
timestamp_format,
(views * ppview) AS totalviews,
(clicks * ppclick) AS totalclicks,
((views * ppview) + (clicks * ppclick)) AS grandtotal
FROM advertisements a;
[/snip]
Use variables;
http://dev.mysql.com/doc/refman/5.1/en/set-statement.html
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]