MySQL Forums
Forum List  »  Full-Text Search

Divide(Math) within a subquery
Posted by: Sam Brinley
Date: April 18, 2006 02:36PM

select distinct a.error, jny.JAN, fby.FEB, mch.MAR from
(select error, sum(value) JAN from tb_sum where month = '200601' group by error) jny,
(select error, sum(value) FEB from tb_sum where month = '200602' group by error) fby,
(select error, sum(value) MAR from tb_sum where month = '200603' group by error) mch,
tb_sum a
where jny.error = fby.error
and jny.error = mch.error
and jny.error = a.error
group by a.error;

Displays like this...

+-------+------+-------+------+
| error | JAN | FEB | MAR |
+-------+------+-------+------+
| err1 | 376 | 885 | 993 |
| err2 | 6939 | 13287 | 4366 |
| err3 | 5433 | 12401 | 5329 |
| err4 | 365 | 896 | 913 |
| err5 | 496 | 1377 | 1355 |
| err6 | 42 | 89 | 94 |
| err7 | 220 | 489 | 499 |
| err9 | 215 | 585 | 442 |
+-------+------+-------+------+

However I want to divide all of these by another table. For instance the JAN err1 block is 376. I want to divide the 376 (and all else in the jan column) by a value in another table.

select days from tb_month where month = '1';

+------+
| days |
+------+
| 31 |
+------

Any ideas?

Thanks,
Sam

Options: ReplyQuote


Subject
Views
Written By
Posted
Divide(Math) within a subquery
11358
April 18, 2006 02:36PM


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.