Re: [SQL ] 對應不同條件的SUM()

作者: cutekid (可愛小孩子)   2019-01-24 14:01:36
select Field1,
sum(
Field2 *
case when Field1 like 'Condition1' then val1
when Field1 like 'Condition2' then val2
end
)
from table
where Field1 like 'Codition1' or Field1 like 'Condition2'
group by Field1
※ 引述《licheer (Keep The Faith)》之銘言:
: 資料庫名稱:MSSQL
: Select Field1, SUM(Field2 * val) // val 變數
: From Table
: Where
: Field1 like 'Condition1'
: or
: Field1 like 'Condition2'
: Group by Field1
: Field0 Field1 Field2 val1 val2
:
作者: licheer (Keep The Faith)   2019-01-24 21:17:00
可以了,謝謝,不過有碰到困難了,有加新條件

Links booklink

Contact Us: admin [ a t ] ucptt.com