普通方法:
select product_id,a.sell_num-b.sell_num min_num from (select * from 表 A where time=时间A) a left join (select * from 表 A where time=时间B) b on a.product_id=b.product_id
如果产品比较少的话 这种效率比较高
select product_id,(select A.sell_num=b.sell_num from 表 B where time=B and a.product_id=b.product_id) min_num from 表 A where time=时间A
SELECT A.*, (A.sell_num-B.sell_num) as min_num from (SELECT * from 表 WHERE time=时间A) as A left join (select product_id, sell_num from 表 where time=时间B) as B on A.product_id=B.product_id;
这个语式,好像效率太低了,有大神指点吗?