a表
名称 价格
a1 a2
b表
名称 价格
b1 b1
b1 b2
a.a1 =b.b1
a.a2=b.b1+b2
想求出在a.a1 =b.b1 的情况下, a.a2!=b.b1+b2
首先union 会过滤重复的,加入a和b里面的 价格之和 相同,且 名称相同 就只会剩余一条显示,再用group by 分组,求得名称不止一条的,就代表不相同
b表的数据有点乱,我改下b表 名称 价格 b1 b3 b1 b2
a.a2!=b.b3+b2
select * from a1, (select b.mingcheng, sum(b.jiage) jiage from b2 b group by jiage) b where a.mingcheng = b.mingcheng and a.jiage != b.jiage;
---
先计算出b表中的数据,然后在和A表进行关联。