我有下表: -
我可以得到: -
使用简单的SQL:
Select Grade, sum(Qty) Qty, sum(Length) Length
from TableA
where
Serial like 'U4%'
但我需要的是: -
2E级是基于某些条件,即超过2级的15%津贴。工作如下: -
15% of Grade 1 => 15% x 305 = 46
Therefore, 2E is 190 (236-46).
我很新鲜&需要帮助我怎么做这个分裂?
感谢。
答案 0 :(得分:0)
试试这个
Select Grade, sum(Qty) Qty, sum(Length) Length
from TableA
where
Serial like 'U4%'
Unoin All
Select * from
(
Select Grade, null , sum(Length) - ((15/100) * sum(qty)) Length
from TableA
where
Serial like 'U4%'
) AS T
where grade=2