Home » Other » Training & Certification » SQL-aggregate function (show total in separate column)
SQL-aggregate function Tue, 16 October 2007 14:39
 amitdumbre27 Messages: 4Registered: 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```

[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
 Michel Cadot Messages: 64852Registered: March 2007 Location: Nanterre, France, http://... Senior MemberAccount Moderator
Make sure that lines of code do not exceed 80 characters when you format. Use the "Preview Message" button.

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
 Littlefoot Messages: 21103Registered: June 2005 Location: Croatia, Europe Senior MemberAccount 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
 Michel Cadot Messages: 64852Registered: March 2007 Location: Nanterre, France, http://... Senior MemberAccount 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: Tue May 30 04:19:35 CDT 2017

Total time taken to generate the page: 0.07773 seconds