如何编写SQL查询或存储过程以获取下表?
TRANCODE | SECTYPE | QUANTITY | TRADEAMOUNT
BY CSEU 1609 19999.87
SL CSEU 609 7094.85
SQL查询计算:
QTY 1609-609=1000
AVG = 19999.87/1609 =12.43
TRADEAMONUT = QTY * AV = ?
使用数量的和:
SUM
( CASE
WHEN TranCode ='by' THEN CAST(Quantity as FLOAT)
WHEN TranCode ='ss' THEN CAST(Quantity as FLOAT)
WHEN TranCode ='sl' THEN CAST(Quantity as FLOAT) * -1
WHEN TranCode ='cs' THEN CAST(Quantity as FLOAT) * -1
END)
如何在SQL查询中使用数学计算?