MySQL Forums
Forum List  »  Newbie

SQL Query Question
Posted by: Ian Barnes
Date: April 12, 2005 03:19PM

Hi,

Im making a query and im stuck with something at the moment. Here is a sample of my query

select domain, count(id) as count, sum(bytes) as bytes, if(isspam,sum(bytes),0) as spams from data;

now the result would be as follows:

---------------------------------------------------
| Domain | Count | Bytes | Spams |
---------------------------------------------------
mysql.com 560 7788662 7788662

Whereas it should output

---------------------------------------------------
| Domain | Count | Bytes | Spams |
---------------------------------------------------
mysql.com 560 7788662 123789

I dont know if that makes sense, ill try and explain more:

The if(isspam) statement is ment to increase the size of spams if the current entry has a "1" in the isspam field. What happens now is that if it matches once, it totals everything and hense the two sizes are the same.

Is there any way that I can achieve this? I want to have an over total (Bytes) and then a Spam total (Spams), the Spams must be lower as not all entries are spam, only some of them.

Regards,
Ian

Options: ReplyQuote


Subject
Written By
Posted
SQL Query Question
April 12, 2005 03:19PM
April 12, 2005 04:38PM
April 12, 2005 10:41PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.