Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2010
    Posts
    153

    Smile Unanswered: calculating sum.

    Hi,
    i have a doubt. I want to calculate sum depending upon the data.
    I have a table called student and it has three fields namely Name, subject, Marks.


    Name Subject Marks
    ------- -------------- ------------
    Raj english1 80
    Raj english2 75
    sunny history 87
    dhiraj english1 90

    i want a query which displays result like
    Name Subject Marks
    ------ ----------- --------
    raj english1 80
    raj english2 75
    -----------
    155


    we can use alias for any of teh columns. i just want to retrieve data whcih would be calculatign sum of the marks for 'Raj'.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Displaying totals and subtotals should be handled by your reporting tool. It is what is considered "presentation logic", and should not be encoded into your sql script.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    which is why microsoft added WITH ROLLUP to its sql syntax

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Sep 2010
    Posts
    153
    i want result as the sum of two numbers. e.i from the above example i want result as 155. Ok i don't want to display, if i want result only thn??

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by sunny_007 View Post
    if i want result only thn??
    SELECT SUM(marks) FROM student WHERE name = 'raj'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •