日期:2014-05-18  浏览次数:20477 次

对比两张表的数量
table_A

ID Name Quantity
1 apple 5
2 banana 1
3 orange 1

table_B

ID Name Quantity
1 apple 2
2 banana 1
3 orange 1

查找出table_A的信息条件为:table_A.Quantity-table_B.Quantity>0

结果为:

ID Name Quantity
1 apple 5

------解决方案--------------------
select * from table_A a inner join table_B b on a.Name =b.Name 
where a.Quantity-b.Quantity>0
------解决方案--------------------
SQL code

select a.id,a.name,a.quantity from table_a a join table_b on a.id=b.id where table_A.Quantity-table_B.Quantity>0

------解决方案--------------------
SQL code
select a.id,a.name,a.quantity from table_a a left join table_b b on a.id=b.id where a.Quantity-b.Quantity>0