第四列我用了一个子查询并命名为ssum,并且想用于两列的相减计算,然后发现直接写ssum并不合乎语法,想计算必须重写一遍这个子查询。想问一下,这种情况必须再写一遍子查询么,有没有什么重用的方法?
select m.id,m.name,m.quantity,(select sum(c.quantity) from ctable as c where mid =m.id) as ssum,(m.quantity-(select sum(c.quantity) from ctable as c where mid =m.id)) as jian
from mtable as m