日期:2014-05-18 浏览次数:20553 次
select fd_shortenedform,fd_spec, ( select sum(number) as number from [order] where refund_status ='NO_REFUND' and (outer_iid = tb_goods.fd_spec or outer_sku_id = tb_goods.fd_spec) ) as fd_number from tb_goods
select fd_shortenedform,fd_spec, ( select sum(number) as number from [order] where refund_status ='NO_REFUND' and (outer_iid = tb_goods.fd_spec or outer_sku_id = tb_goods.fd_spec) ) as fd_number from tb_goods with(index(index_name)) --加个强行使用索引试一下。实在不行就分成两次然后再累加求和 SQL 语句的长短和效率不是成正比的
------解决方案--------------------
union all 和OR理论上功能是不同的,如果两个条件都符合的记录,union all会计算两次造成SUM虚增