开发者

In SQL how I can multiply results obtained in rows into results obtained in columns

Exist a mode or method to obtained that result? please seem my image in the post

In SQL how I can multiply results obtained in rows into results obtained in columns

I want my result is a product of numbers in vertical (b开发者_运维知识库lack line) multiplied by number horizontal (red line)


Please try this:

select cast(exp(sum(log(ExpPeso))) as float) as myresult1, (tda1*tda2*tda3*tda4) as reslutset2  
from TableName


If you would normalize your data by extracting the numbered columns into a table such as

Matrix
Name  Value
Tda1    94.5
Tda2    21.1
Tda3    53.4
Tda4    21.1

And assuming original table is named table, with columns tda value in column called name and value to multiply with named expression (sorry can't read your column names)

Then you could

SELECT matrix.value * table.expression
FROM matrix m INNER JOIN table t
    ON m.name = t.tda_value

If you can not change structure then in standard SQL (IMHO) you will have to do case

SELECT 
      CASE t.tda_value 
          WHEN "Tda1" THEN Tda1
          WHEN "Tda2" THEN Tda2
          WHEN "Tda3" THEN Tda3
          WHEN "Tda4" THEN Tda4
          ELSE 0
      END * t.expression
FROM table

Notes:

  • you might want to have ELSE NULL (or skip else).
  • some databases have extensions to standard that would allow you to have dynamic columns to rows

EDIT: Of course and at the risk of stating too obvious, at the end you can do a SUM of the above query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜