is there a PRODUCT function like there is a SUM function in Oracle SQL?

后端 未结 6 1821
别跟我提以往
别跟我提以往 2020-12-03 04:15

I have a coworker looking for this, and I don\'t recall ever running into anything like that.

Is there a reasonable technique that would let you simulate it?

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 04:22

    DECLARE @a int
    SET @a = 1
    -- re-assign @a for each row in the result
    -- as what @a was before * the value in the row
    SELECT @a = @a * amount
    FROM theTable
    

    There's a way to do string concat that is similiar:

    DECLARE @b varchar(max)
    SET @b = ""
    
    SELECT @b = @b + CustomerName
    FROM Customers
    

提交回复
热议问题