Home » SQL & PL/SQL » SQL & PL/SQL » How to find sums??????
How to find sums?????? [message #7414] Thu, 12 June 2003 03:36 Go to next message
sachin kumar gupta
Messages: 157
Registered: March 2003
Senior Member
Hello,

I want to find sum in foll O/P form:

Col1 Col2 Col3 Col4

fdg ert er 12
wer rfg 14
--------
Sum 26

dsaf fdg g 3
sf ewr 13
----------
Sum 16

fg 34 234 18

---------------------------------------------
Total 60

& this one also:

Col1 Sum(Col2)
sfsdf 2
dwfwed 4
sdfsdf 5
fsdf 5
-----------
Sum 16

Kindly suggest me the methods for both the queries.

Thanks in Adv.

Sachin
Re: How to find sums?????? [message #7417 is a reply to message #7414] Thu, 12 June 2003 08:43 Go to previous messageGo to next message
MikeT
Messages: 11
Registered: August 2002
Junior Member
Need more info...basically, from what you have there:

Query 1:
select sum(Col4)
from yourtable

Query 2:
select sum(Col2)
from yourtable

...but something tells me this is not what you really want.
Re: How to find sums?????? [message #7451 is a reply to message #7417] Sun, 15 June 2003 22:55 Go to previous messageGo to next message
sachin kumar gupta
Messages: 157
Registered: March 2003
Senior Member
Eg. total purchasing for month Jan., total purchasing for month B,...
I want sum of all purchasing for all months. just below where the Purchasing column.

Hope u got my point,

Sachin
Re: How to find sums?????? [message #7460 is a reply to message #7451] Mon, 16 June 2003 07:30 Go to previous messageGo to next message
Mike T
Messages: 32
Registered: August 2002
Member
In SQL Plus:

CLEAR BREAKS
CLEAR COMPUTES
BREAK ON REPORT
COMPUTE SUM OF 'purchasing' ON REPORT

select month, sum(purchasing) as purchasing
from table
group by month;

If you have more fields you want to SELECT, add them to the GROUP BY, and add "BREAK ON MONTH" and a "COMPUTE SUM" for your subtotals by Month:

CLEAR BREAKS
CLEAR COMPUTES
BREAK ON 'month' SKIP 1
COMPUTE SUM OF 'purchasing' ON 'month'
COMPUTE SUM OF 'purchasing' ON REPORT

select field1, field2, month, sum(purchasing) as purchasing
from table
group by field1, field2, month;

Hope that helps
-- Mike
Re: How to find sums?????? [message #7500 is a reply to message #7460] Wed, 18 June 2003 00:35 Go to previous message
sachin kumar gupta
Messages: 157
Registered: March 2003
Senior Member
Thanx Mike,
It's working!!!!

Bye,
Sachin
Previous Topic: Re: Subquery + where clause
Next Topic: subquery problem
Goto Forum:
  


Current Time: Fri Apr 26 03:20:16 CDT 2024