473,499 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mysql ROUND() inside SUM()

1 New Member
I have a table1 as:
id(int); percent(double,2); a(double,2); b(double,2); c(double,2);.....z(double,2)
1; 0.12; 1.33; 1.26; 1.89;........
2; 0.11; 1.55; 1.22; 1.56;........
:
:
and many rows

i always need to sum up query as:
SELECT SUM(ROUND(a*percent,2)+ROUND(b*percent,2)+ROUND(c* percent,2)) AS sum_abc, SUM(ROUND(d*percent,2)+ROUND(e*percent,2)+ROUND(f* percent,2)) AS sum_def ...... FROM table1;

My problem is:
I found that doing many ROUND() inside SUM() in the query are slower, as it may sum up to few thousand rows. As seen, it Rounds in every single row.
So, i try to store a*percent value in new column per_a, for every a......z:
id(int); a(double,2); per_a(double,2); b(double,2); per_b(double,2);.....per_z(double,2)

So i can write my query as:
SELECT SUM(per_a+per_b+per_c) AS sum_abc, SUM(per_d+per_e+per_f) AS sum_def ...... FROM table1;

so that i dont need to round up. BUT now, my table columns become more and bigger in size, double size of the original.
May i know which one is suitable and better in performance?
Apr 21 '07 #1
0 2330

Sign in to post your reply or Sign up for a free account.

Similar topics

19
8674
by: Westcoast Sheri | last post by:
To keep track of how many fruits my visitors buy, I use a mySQL database (2 columns: "fruit" and "quantity")....so can we make these following mySQL queries work somehow? (visitor buys 5...
6
4640
by: aa | last post by:
I use the following fragment of code to output datf from MySQL: ====================================================== $chan = mysql_connect ($db_host, $username, $password); mysql_select_db...
0
2691
by: Philip Stoev | last post by:
Hi all, Please tell me if any of this makes sense. Any pointers to relevant projects/articles will be much appreciated. Philip Stoev http://www.stoev.org/pivot/manifest.htm ...
0
3923
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
4
5442
by: Bob Bryan | last post by:
I am using a select statement to obtain a result set back with aggregated data. The problem is that I am seeing column data with 11 to 13 digits after the decimal point. I tried using the STR...
10
2113
by: smorrey | last post by:
Hello all, this might better be suited for the MySQL newsgroup, but I figured I'ld post here and see if anyone can help me. I'm trying to create a simple transaction handling system where users...
1
3273
by: dhutton | last post by:
Hello - Question... What would be the best way to round a number off and change it to currency with the below statement? SELECT Cycle AS BillCycle, SUM(PrevBillAmt) - SUM(Payment) +...
5
1692
by: ScottCase | last post by:
Hello, I have this sql statement and it works fine with mysql v4 $query = "SELECT id, name, jv_signups, mem_signups, ( SELECT SUM( jv_signups ) ) + ( SELECT SUM( mem_signups ) ) AS total...
5
1419
by: inexion | last post by:
Hello, I'll try to explain what I'm trying to accomplish here, hopefully not too bad a task. Basically I have an existing table with data that will be operated on to form new records etc... ...
0
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.