Home » Other » Training & Certification » SQL-aggregate function (show total in separate column)
icon1.gif  SQL-aggregate function [message #274665] Tue, 16 October 2007 14:39 Go to next message
amitdumbre27
Messages: 4
Registered: October 2007
Location: mumbai
Junior Member
I want to show the total of all subjects in a separate column(total) according to student, in short i want to feel the total column. Please help me out for the SQL quiry
SQL> select * from student;

ROLL_NO    NAME      MATHS      SCIENCE    ENGLISH TOTAL
---------- --------- ---------- ---------- ------- ---------
         1 amit              80         85      90
         2 nitin             60         65      80
         3 arasan            70         75      85
         4 avi               60         65      75



[mod-edit]Added code tags.

[Updated on: Wed, 17 October 2007 00:53] by Moderator

Report message to a moderator

Re: SQL-aggregate function [message #274670 is a reply to message #274665] Tue, 16 October 2007 14:54 Go to previous messageGo to next message
Michel Cadot
Messages: 64132
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read and follow OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format. Use the "Preview Message" button.
Please always post your Oracle version (4 decimals).

Have a look at SUM function.

Regards
Michel
Re: SQL-aggregate function [message #274676 is a reply to message #274670] Tue, 16 October 2007 15:26 Go to previous messageGo to next message
Littlefoot
Messages: 20900
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Hm, but ... this isn't Oracle nor programming problem, it is about a common sense. Something like, "if a chicken stands on one leg, it weights 4 kg. How much does it weight if it stands on both legs?".

We do have to sum those values, but pure '+' would be quite enough. Wouldn't it?
SELECT name, maths + science + english total
FROM student
Re: SQL-aggregate function [message #274761 is a reply to message #274676] Wed, 17 October 2007 01:34 Go to previous message
Michel Cadot
Messages: 64132
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Oh, the sum is a sum of columns for each roll_no and not an overall sum, I didn't read it like that.

Regards
Michel
Previous Topic: Trigger to work in a single record
Next Topic: order of steps to complete OCP
Goto Forum:
  


Current Time: Wed Dec 07 20:44:34 CST 2016

Total time taken to generate the page: 0.08233 seconds