我有一个简单的学生表。
name | amount | vdate
Josh | 15 | 01.01.2020
Steve | 25 | 05.04.2008
Josh | 40 | 01.01.2022
我想要做的是彼此减去 Josh 值。
我写了这个查询,但它不起作用
select name , sum(b.amount-a.amount) diff from
select name,amount from student a where name = 'Josh' and vdate='01.01.2020'
union all
select name,amount from student b where name = 'Josh' and vdate = '01.01.2022')
group by name
预期结果是:
name | diff
Josh | 25
Steve| 25