SQLite如何计算相同table的两个变量之间的差异

SQLite How to calculate a difference between two variables of the same table

我是 SQL 的新手,考虑到以下 table。

理想情况下我会得到 this result table (calculation between parentheses for clarification) 感谢您的帮助!

这看起来像 union all 逆透视,然后聚合:

select asset, sum(amount) total_amount
from (
    select in_asset as asset, in_amount as amount from mytable
    union all
    select out_asset, - out_amount from mytable
) t
group by asset