473,408 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Using the MySQL SUM() function

296 100+
My SQL query is -->

SELECT sum(bookings),sum(invoices) FROM alaqary WHERE alasas="WQ"

I am finding the sum of two fields .

Is there any better way ?
Mar 7 '07 #1
12 10246
gauravgmbhr
107 100+
My SQL query is -->

SELECT sum(bookings),sum(invoices) FROM alaqary WHERE alasas="WQ"

I am finding the sum of two fields .

Is there any better way ?

try this

SELECT s1.Sum, s2.Sum
FROM (SELECT sum(bookings) Sum , alasas
FROM alagary) s1,
(SELECT sum(invoices) Sum , alasas
FROM alagary) s2,
WHERE s1.alasas='WQ'
AND s2.alasas='WQ'
Mar 7 '07 #2
gauravgmbhr
107 100+
try this

SELECT s1.Sum, s2.Sum
FROM (SELECT sum(bookings) Sum , alasas
FROM alagary) s1,
(SELECT sum(invoices) Sum , alasas
FROM alagary) s2,
WHERE s1.alasas='WQ'
AND s2.alasas='WQ'
but i guess ur code will also work
wats exactly u r lookin for
Mar 7 '07 #3
pankajit09
296 100+
try this

SELECT s1.Sum, s2.Sum
FROM (SELECT sum(bookings) Sum , alasas
FROM alagary) s1,
(SELECT sum(invoices) Sum , alasas
FROM alagary) s2,
WHERE s1.alasas='WQ'
AND s2.alasas='WQ'
Why to make it so complex ?
Mar 7 '07 #4
pankajit09
296 100+
BUT I GUESS UR CODE WILL ALSO WORK
WATS EXACTLY U R LOOKIN FOR
I want to avoid using SUM in all the fields.
Mar 7 '07 #5
gauravgmbhr
107 100+
I want to avoid using SUM in all the fields.

u want to get the sum of all entries in ur table but u dun wanna use aggregate functions?????

is that what u want
Mar 7 '07 #6
pankajit09
296 100+
U WANT TO GET THE SUM OF ALL ENTRIES IN UR TABLE BUT U DUN WANNA USE AGGREGATE FUNCTIONS?????

IS THAT WHAT U WANT
NO

I wanna use Aggregate functions with a different way if possible ?
Mar 7 '07 #7
gauravgmbhr
107 100+
NO

I wanna use Aggregate functions with a different way if possible ?

i know what u don't want but
i am not able to get what u want
plz explain briefly

well i explained a method above in my previous post
Mar 7 '07 #8
gauravgmbhr
107 100+
i know what u don't want but
i am not able to get what u want
plz explain briefly

well i explained a method above in my previous post

are u talking bout something related to complete table scan that u don't want
Mar 7 '07 #9
pankajit09
296 100+
are u talking bout something related to complete table scan that u don't want
NO

I just don't want to use SUM with every field of the table.

Now you got ?
Mar 7 '07 #10
NO

I just don't want to use SUM with every field of the table.

Now you got ?
hi dear,
if you dont want realy user SUM() for your field to return back the some value,
i think you have to use PROCEDURE s or FUNCTION in your Database.

then just use CALL function to use the functions.

search and read more about user defiened functions and store procedure in your DBMS.

it will looks like this.

mysql> delimiter //

mysql> CREATE PROCEDURE mysum (IN field INT,OUT res INT)
-> BEGIN
-> SELECT SUM( field ) INTO res FROM t;
-> END;
-> //
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter ;
Mar 7 '07 #11
gauravgmbhr
107 100+
NO

I just don't want to use SUM with every field of the table.

Now you got ?

U want to Do the SUM but Dont Wanna Use Sum()????

TEll me what u wanna Do , Not wat U dont wanna Do.
i understood wat u dont Wanna Do, But didnt Get Wat u wanna Do
Mar 7 '07 #12
gauravgmbhr
107 100+
U want to Do the SUM but Dont Wanna Use Sum()????

TEll me what u wanna Do , Not wat U dont wanna Do.
i understood wat u dont Wanna Do, But didnt Get Wat u wanna Do

YA the Guy Before Me is right

Try This
Stored Procedures
Mar 7 '07 #13

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

Similar topics

19
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...
2
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum...
0
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default...
3
by: fra | last post by:
hi everybody, i got a strange problem with a simple mysql query in php. simply, it doesn't work on my page (while it does through phpmyadmin): there's the query: $sql=" SELECT operatore, azione,...
3
by: Auddog | last post by:
I have the following query that works in mysql: select id, order_no, price, count(item_no), sum(price) from production WHERE item_no = '27714' group by item_no; When I setup my query in php,...
3
by: printline | last post by:
Hello All I need a little help with a phph script to display some specific data from a mysql table. I have a mysql table with 4 columns and 10 rows. I want to display fx. data from row 4, 6, 8...
5
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
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
by: silversubey | last post by:
I am trying to convert mssql triggers to mysql. I am very new to Mysql and would like some help with my code. My queries work but there has to be a more efficient way to write them. I would greatly...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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,...

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.