小问题,路过的进来帮下。谢谢
表A
a b
---------------
a1 1
a2 3
a3 4
表B
a b
---------------
a1 3
a2 2
a5 3
出来结果 想
a b c
----------------------
a3 4 null
a2 3 (3-2)/2
a1 1 (1-3)/3
注:表B的 c 值是 A表的b和B表的b的值。
------解决方案--------------------select A.a,
A.b,
c=(A.b-B.b)/B.b
from A
left join B on A.a=B.a
order by A.b desc
------解决方案--------------------select a.*,c=case when b.b is not null then (a.b-b.b)/b.b end from a left join b on a.a=b.a order by a.a desc