0

there is a way for aggregate values in multiplication (*) operator rather than + Operator?. for this example the result will be 140 (4*5*7=140)

SELECT  SUM(V) --*?
FROM    ( SELECT    4 V
          UNION ALL
          SELECT    5
          UNION ALL
          SELECT    7
        ) Q
mordechai
  • 829
  • 1
  • 7
  • 23
  • Nothing built in. You'll probably need to use a cursor and do the calculation yourself. Otherwise do it on the client. But also note range of ints on SQL Server: you'll not need many rows before overflowing (compound multiplication of even small values greater than one gets big quickly). – Richard Jan 19 '17 at 10:55
  • where are these values stored? – McNets Jan 19 '17 at 10:57

1 Answers1

1
       select *
    into #a --*?
    FROM    ( SELECT    4 V
              UNION ALL
              SELECT    5
              UNION ALL
              SELECT    7
            ) Q

 select EXP(SUM(LOG(v))) As value from #a

or

SELECT  EXP(SUM(LOG(v)))
FROM    ( SELECT    4 V
          UNION ALL
          SELECT    5
          UNION ALL
          SELECT    7
        ) Q
Chanukya
  • 5,833
  • 1
  • 22
  • 36