Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Regarding sum of a column

Regarding sum of a column

Scheduled Pinned Locked Moved Database
database
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrcsn
    wrote on last edited by
    #1

    Hi , im using two tables , tbl1,tbl2 . im multiplying tb1.column1 ,tbl2.column and displaying as result . i want to display sum(column1.column2) as total (another column). can any body tell me the query for this , Thank u. C.S.n

    M P C 3 Replies Last reply
    0
    • M mrcsn

      Hi , im using two tables , tbl1,tbl2 . im multiplying tb1.column1 ,tbl2.column and displaying as result . i want to display sum(column1.column2) as total (another column). can any body tell me the query for this , Thank u. C.S.n

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      I feel I have the wrong handle on your problem but... If you want the additional of col1 + col2 then it is the same method as the multiply If you are after the sum of all the records preceding the current record then you need to look into running totals (depends on your DB) if you want the sum of the 2 cols included in the result set you need to do the query 2 times, 1 to get the total into a var and the seconed to include it in your result set You really need to define your problem a little clearer. Remember we have not gone through the process of getting where you are stuck and do not have the code in front of us.

      Never underestimate the power of human stupidity RAH

      M 1 Reply Last reply
      0
      • M mrcsn

        Hi , im using two tables , tbl1,tbl2 . im multiplying tb1.column1 ,tbl2.column and displaying as result . i want to display sum(column1.column2) as total (another column). can any body tell me the query for this , Thank u. C.S.n

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        Depending on whether you are trying to just add the two columns together, or add the sum of the columns together, you could either do:

        select tbl1.column1 + tbl2.column as summation

        or

        select sum(tbl.column1 + tbl2.column) as total

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        1 Reply Last reply
        0
        • M mrcsn

          Hi , im using two tables , tbl1,tbl2 . im multiplying tb1.column1 ,tbl2.column and displaying as result . i want to display sum(column1.column2) as total (another column). can any body tell me the query for this , Thank u. C.S.n

          C Offline
          C Offline
          ChandraRam
          wrote on last edited by
          #4

          mrsuman wrote:

          im using two tables , tbl1,tbl2 . im multiplying tb1.column1 ,tbl2.column and displaying as result . i want to display sum(column1.column2) as total (another column). can any body tell me the query for this ,

          Is this what you are looking for: select tbl1.column1,tbl2.column2,tbl1.column1*tbl2.column2 as Result, sum(tb1.column1*tbl2.column2) as Total This query will have the Total column as the same value for all the rows.

          M 2 Replies Last reply
          0
          • C ChandraRam

            mrsuman wrote:

            im using two tables , tbl1,tbl2 . im multiplying tb1.column1 ,tbl2.column and displaying as result . i want to display sum(column1.column2) as total (another column). can any body tell me the query for this ,

            Is this what you are looking for: select tbl1.column1,tbl2.column2,tbl1.column1*tbl2.column2 as Result, sum(tb1.column1*tbl2.column2) as Total This query will have the Total column as the same value for all the rows.

            M Offline
            M Offline
            mrcsn
            wrote on last edited by
            #5

            Hi, Sorry for late reply . here im having price of seat in one table and no. of seats in another table. i want to get result(Price * No. Of Seats ) as amount to pay as one cloumn and total of these values as another column. i think now u can understand my problem .. can u tell me the query how can i do this . thanks .

            1 Reply Last reply
            0
            • M Mycroft Holmes

              I feel I have the wrong handle on your problem but... If you want the additional of col1 + col2 then it is the same method as the multiply If you are after the sum of all the records preceding the current record then you need to look into running totals (depends on your DB) if you want the sum of the 2 cols included in the result set you need to do the query 2 times, 1 to get the total into a var and the seconed to include it in your result set You really need to define your problem a little clearer. Remember we have not gone through the process of getting where you are stuck and do not have the code in front of us.

              Never underestimate the power of human stupidity RAH

              M Offline
              M Offline
              mrcsn
              wrote on last edited by
              #6

              Hi , i will explain where i stuck .. i'm having two tables transaction and pricing . in transaction table i'm having number of seats column and price/seat in pricing . here i want a column which displays (no. of seats * price/ seat ) and sum of all these rows as next row or separate column.i'm getting(no. of seats * price/seat) using join but im not getting how to do sum of all these rows . can u tell me this pls .. thanks csn

              1 Reply Last reply
              0
              • C ChandraRam

                mrsuman wrote:

                im using two tables , tbl1,tbl2 . im multiplying tb1.column1 ,tbl2.column and displaying as result . i want to display sum(column1.column2) as total (another column). can any body tell me the query for this ,

                Is this what you are looking for: select tbl1.column1,tbl2.column2,tbl1.column1*tbl2.column2 as Result, sum(tb1.column1*tbl2.column2) as Total This query will have the Total column as the same value for all the rows.

                M Offline
                M Offline
                mrcsn
                wrote on last edited by
                #7

                i will explain where i stuck .. i'm having two tables transaction and pricing . in transaction table i'm having number of seats column and price/seat in pricing . here i want a column which displays (no. of seats * price/ seat ) and sum of all these rows as next row or separate column.i'm getting(no. of seats * price/seat) using join but im not getting how to do sum of all these rows . can u tell me this pls .. thanks csn

                C 1 Reply Last reply
                0
                • M mrcsn

                  i will explain where i stuck .. i'm having two tables transaction and pricing . in transaction table i'm having number of seats column and price/seat in pricing . here i want a column which displays (no. of seats * price/ seat ) and sum of all these rows as next row or separate column.i'm getting(no. of seats * price/seat) using join but im not getting how to do sum of all these rows . can u tell me this pls .. thanks csn

                  C Offline
                  C Offline
                  ChandraRam
                  wrote on last edited by
                  #8

                  Can you give an example output you want from this query?

                  M 1 Reply Last reply
                  0
                  • C ChandraRam

                    Can you give an example output you want from this query?

                    M Offline
                    M Offline
                    mrcsn
                    wrote on last edited by
                    #9

                    Thanks for u r reply .. ex : result ------ 200 350 500 400 250 in next row or separate column i want sum of these rows .

                    C 1 Reply Last reply
                    0
                    • M mrcsn

                      Thanks for u r reply .. ex : result ------ 200 350 500 400 250 in next row or separate column i want sum of these rows .

                      C Offline
                      C Offline
                      ChandraRam
                      wrote on last edited by
                      #10

                      If having it in the same row is Ok, then my earlier query should work for you (providing of course that you specify the correct join condition).

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups