Use if statements: Your query would then look like this: SELECT SUM(IF(cur = 'SEK',amount,0)), SUM(IF(cur = 'EUR',amount,0)) FROM table1 WHERE ...
The if statement has three properties, the first is the condition, the second what to do if true, the third, is what to do if false. Hope this helps, Yoed -----Original Message----- From: Kristian Niemi [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 28, 2004 12:25 AM To: [EMAIL PROTECTED] Subject: SUM same field twice in one SELECT? Hi, I've just started to dabble with MySQL, creating a database as much for actual use, as for learning experience. Thus, if my question is a really basic one, for which there is a manual page, please just refer me to it. :) So, I have this table, let's call it table1, in which I amongst other fields have the two fields amount and cur. Obviously I use `amount' to store a amount (a price, as it were), and `cur' to store in which currency the price is. If I do a query similar to: SELECT SUM(amount) FROM table1 GROUP BY cur; I get the total sum for the different currencies, but, and here's my question, what if I want to multiply the different currencies with their respective exchange rate and get the going total price for the _total_ sum, not just `total per currency'? Might this be achieved by some sort of sub-select? The function of what I'd like to do would be something similar to: SELECT (SUM(amount) FROM table1 WHERE cur = 'SEK'), (SUM(amount) FROM table1 WHERE cur = 'EUR') FROM table1; But obviously that doesn't work. Any tips would be appreciated! h: Kristian -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]