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. Product of Salary

Product of Salary

Scheduled Pinned Locked Moved Database
databasehelpquestioncareer
20 Posts 8 Posters 2 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hello Everybody, As we find the Sum of Salary from Emp Table. SQL Query : Select Sum(Emp) from Emp; Now I want to get the product of Salary : Product means (first sala * Second Sal * Third Salary * ...... * Last salary); How can i use with the help of SQL Command. I Do't want to USE PL/SQL Command. Thanks

    If you can think then I Can.

    S P J P R 6 Replies Last reply
    0
    • L Lost User

      Hello Everybody, As we find the Sum of Salary from Emp Table. SQL Query : Select Sum(Emp) from Emp; Now I want to get the product of Salary : Product means (first sala * Second Sal * Third Salary * ...... * Last salary); How can i use with the help of SQL Command. I Do't want to USE PL/SQL Command. Thanks

      If you can think then I Can.

      S Offline
      S Offline
      Simon_Whale
      wrote on last edited by
      #2

      assuming as you haven't given a table structure, that there is a column that has the first salary etc in.

      select salary_type, sum(emp) from emp group by salary_type

      if this doesn't help you, you will need to provide more information i.e. table structures etc.

      As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.

      L 1 Reply Last reply
      0
      • S Simon_Whale

        assuming as you haven't given a table structure, that there is a column that has the first salary etc in.

        select salary_type, sum(emp) from emp group by salary_type

        if this doesn't help you, you will need to provide more information i.e. table structures etc.

        As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I think u are not find the meaning of my question. I want to Get the Multiplcation of All Employee Salary. For Example :

        Ename Sal


        Anu 10
        Minu 20
        Tusar 20
        Piter 10

        Now I want to get the Multiplication of All Salary : (10 * 20 * 20 * 10) With the help of SQL. I Do't want to use PL/SQL Commands. Thank

        If you can think then I Can.

        B 1 Reply Last reply
        0
        • L Lost User

          Hello Everybody, As we find the Sum of Salary from Emp Table. SQL Query : Select Sum(Emp) from Emp; Now I want to get the product of Salary : Product means (first sala * Second Sal * Third Salary * ...... * Last salary); How can i use with the help of SQL Command. I Do't want to USE PL/SQL Command. Thanks

          If you can think then I Can.

          P Offline
          P Offline
          Pravin Patil Mumbai
          wrote on last edited by
          #4

          Did you try using Cursor, I think that can solve your problem. Hope this helps. All the best.

          L 1 Reply Last reply
          0
          • P Pravin Patil Mumbai

            Did you try using Cursor, I think that can solve your problem. Hope this helps. All the best.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            No, But How can i use cursor for this requirement...

            If you can think then I Can.

            1 Reply Last reply
            0
            • L Lost User

              I think u are not find the meaning of my question. I want to Get the Multiplcation of All Employee Salary. For Example :

              Ename Sal


              Anu 10
              Minu 20
              Tusar 20
              Piter 10

              Now I want to get the Multiplication of All Salary : (10 * 20 * 20 * 10) With the help of SQL. I Do't want to use PL/SQL Commands. Thank

              If you can think then I Can.

              B Offline
              B Offline
              Bernhard Hiller
              wrote on last edited by
              #6

              There is a trick, see http://www.sql-server-performance.com/tips/user_defined_functions_p1.aspx[^]. But somehow your example looks like homework, the product of salaries is just nonsense...

              L 1 Reply Last reply
              0
              • B Bernhard Hiller

                There is a trick, see http://www.sql-server-performance.com/tips/user_defined_functions_p1.aspx[^]. But somehow your example looks like homework, the product of salaries is just nonsense...

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                This Is Just for Knowing Concept to How To Multiply Fields Values. And I Say that i do't want to use PL/SQL.

                If you can think then I Can.

                1 Reply Last reply
                0
                • L Lost User

                  Hello Everybody, As we find the Sum of Salary from Emp Table. SQL Query : Select Sum(Emp) from Emp; Now I want to get the product of Salary : Product means (first sala * Second Sal * Third Salary * ...... * Last salary); How can i use with the help of SQL Command. I Do't want to USE PL/SQL Command. Thanks

                  If you can think then I Can.

                  J Offline
                  J Offline
                  Jorgen Andersson
                  wrote on last edited by
                  #8

                  You can use select exp(sum(ln(sal))) from emp which of course will throw an exception for negative numbers and zero. But that you can easily fix with a case expression. The best solution is of course to create a function to do the job.

                  List of common misconceptions

                  L 1 Reply Last reply
                  0
                  • J Jorgen Andersson

                    You can use select exp(sum(ln(sal))) from emp which of course will throw an exception for negative numbers and zero. But that you can easily fix with a case expression. The best solution is of course to create a function to do the job.

                    List of common misconceptions

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Can u please explain with the form of SQL Query.

                    If you can think then I Can.

                    J B 2 Replies Last reply
                    0
                    • L Lost User

                      Can u please explain with the form of SQL Query.

                      If you can think then I Can.

                      J Offline
                      J Offline
                      Jorgen Andersson
                      wrote on last edited by
                      #10

                      eg_Anubhava wrote:

                      Can u please explain with the form of SQL Query.

                      Well I did. I'll do it again, with extra explanation, and I'll write slowly. You have a table EMP that has a column SAL that you want the product from instead of the sum. Then the query can look like this:

                      SELECT EXP(SUM(LN(SAL)))
                      FROM EMP

                      This query has the drawback that the LN() function will throw an exception for negative numbers and zero. Tip: CASE WHEN and SIGN() will be useful. This can be mathematically written like: A*B = eln(A)+ln(B)

                      List of common misconceptions

                      L 1 Reply Last reply
                      0
                      • L Lost User

                        Can u please explain with the form of SQL Query.

                        If you can think then I Can.

                        B Offline
                        B Offline
                        Bernhard Hiller
                        wrote on last edited by
                        #11

                        eg_Anubhava wrote:

                        Can u please explain with the form of SQL Query.

                        which proves that you did not look at the link I posted above. It is shown there!

                        J 1 Reply Last reply
                        0
                        • J Jorgen Andersson

                          eg_Anubhava wrote:

                          Can u please explain with the form of SQL Query.

                          Well I did. I'll do it again, with extra explanation, and I'll write slowly. You have a table EMP that has a column SAL that you want the product from instead of the sum. Then the query can look like this:

                          SELECT EXP(SUM(LN(SAL)))
                          FROM EMP

                          This query has the drawback that the LN() function will throw an exception for negative numbers and zero. Tip: CASE WHEN and SIGN() will be useful. This can be mathematically written like: A*B = eln(A)+ln(B)

                          List of common misconceptions

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          It is generating an Error while executing this Query. Error Message is : Undefined Function 'LN' in Expression.

                          If you can think then I Can.

                          J 1 Reply Last reply
                          0
                          • L Lost User

                            Hello Everybody, As we find the Sum of Salary from Emp Table. SQL Query : Select Sum(Emp) from Emp; Now I want to get the product of Salary : Product means (first sala * Second Sal * Third Salary * ...... * Last salary); How can i use with the help of SQL Command. I Do't want to USE PL/SQL Command. Thanks

                            If you can think then I Can.

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

                            If you don't want to use any of the built in Oracle commands, then you could achieve this by using a cursor to iterate over the user's salary and keep a running total that way.

                            I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                            Forgive your enemies - it messes with their heads

                            My blog | My articles | MoXAML PowerToys | Onyx

                            1 Reply Last reply
                            0
                            • L Lost User

                              It is generating an Error while executing this Query. Error Message is : Undefined Function 'LN' in Expression.

                              If you can think then I Can.

                              J Offline
                              J Offline
                              Jorgen Andersson
                              wrote on last edited by
                              #14

                              ln() is supported on Oracle since version 8i. If you're using an older version than that, you're having bigger problems than the missing ln() function. But if you by any chance aren't using Oracle despite your numerous references to PL/SQL, then both SqlServer and MSAccess uses log() instead of ln().

                              List of common misconceptions

                              1 Reply Last reply
                              0
                              • B Bernhard Hiller

                                eg_Anubhava wrote:

                                Can u please explain with the form of SQL Query.

                                which proves that you did not look at the link I posted above. It is shown there!

                                J Offline
                                J Offline
                                Jorgen Andersson
                                wrote on last edited by
                                #15

                                And obviously I didn't either. :doh:

                                List of common misconceptions

                                1 Reply Last reply
                                0
                                • L Lost User

                                  Hello Everybody, As we find the Sum of Salary from Emp Table. SQL Query : Select Sum(Emp) from Emp; Now I want to get the product of Salary : Product means (first sala * Second Sal * Third Salary * ...... * Last salary); How can i use with the help of SQL Command. I Do't want to USE PL/SQL Command. Thanks

                                  If you can think then I Can.

                                  R Offline
                                  R Offline
                                  RyanEK
                                  wrote on last edited by
                                  #16

                                  declare @temp table (ename varchar(10), sal int)
                                  insert into @temp values ('Anu', 10)
                                  insert into @temp values ('Minu', 20)
                                  insert into @temp values ('Tusar', 20)
                                  insert into @temp values ('Piter', 10)

                                  select exp(sum(log(sal))) from @temp

                                  L 1 Reply Last reply
                                  0
                                  • R RyanEK

                                    declare @temp table (ename varchar(10), sal int)
                                    insert into @temp values ('Anu', 10)
                                    insert into @temp values ('Minu', 20)
                                    insert into @temp values ('Tusar', 20)
                                    insert into @temp values ('Piter', 10)

                                    select exp(sum(log(sal))) from @temp

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #17

                                    It returns the wrong answer in some cases change the values and then try. the difference of values are in some points.

                                    If you can think then I Can.

                                    R 1 Reply Last reply
                                    0
                                    • L Lost User

                                      It returns the wrong answer in some cases change the values and then try. the difference of values are in some points.

                                      If you can think then I Can.

                                      R Offline
                                      R Offline
                                      RyanEK
                                      wrote on last edited by
                                      #18

                                      Try

                                      SELECT CAST(ROUND(COALESCE(EXP(SUM(LOG(ABS(NULLIF(sal,0))))),0)*SIGN(MIN( ABS(sal)))*(COUNT(NULLIF(SIGN(sal),1))%2*-2+1),0) AS INTEGER)
                                      FROM @temp

                                      L 1 Reply Last reply
                                      0
                                      • R RyanEK

                                        Try

                                        SELECT CAST(ROUND(COALESCE(EXP(SUM(LOG(ABS(NULLIF(sal,0))))),0)*SIGN(MIN( ABS(sal)))*(COUNT(NULLIF(SIGN(sal),1))%2*-2+1),0) AS INTEGER)
                                        FROM @temp

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #19

                                        Briallent Wow Thanks

                                        If you can think then I Can.

                                        1 Reply Last reply
                                        0
                                        • L Lost User

                                          Hello Everybody, As we find the Sum of Salary from Emp Table. SQL Query : Select Sum(Emp) from Emp; Now I want to get the product of Salary : Product means (first sala * Second Sal * Third Salary * ...... * Last salary); How can i use with the help of SQL Command. I Do't want to USE PL/SQL Command. Thanks

                                          If you can think then I Can.

                                          W Offline
                                          W Offline
                                          Wendelius
                                          wrote on last edited by
                                          #20

                                          Hi, Even though you mentioned that you don't want to use PL/SQL you could be interested in this: Custom aggregates in Oracle[^] Best regards, mika

                                          The need to optimize rises from a bad design.My articles[^]

                                          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