日期:2014-05-17  浏览次数:20574 次

这个SQL语句可以再优化一下吗?老是超时已过期
select a.order_id,a.order_number,a.order_date,a.style_number,a.shipment_date,                (select count(order_id) from carton where order_id=a.order_id) packed_count,       (select sum(packed_qty) from carton where order_id=a.order_id) packed_qty,
       (select sum(gross_weight) from carton where order_id=a.order_id) gross_weight,
       (select sum(net_weight) from carton where order_id=a.order_id) net_weight,
       (select sum(vol_cbm) from carton where order_id=a.order_id) total_vol
,
       b.country_name,a.shipment_method_desc,a.terms_desc 
from order_head a 
inner join order_address b on a.order_id=b.order_id and b.address_purpose='DE'
where (1=1) +其他条件

里面有个统计结果,不知道可以再优化一下不,查询时老是超时已过期

------解决方案--------------------
SELECT  a.order_id ,
        a.order_number ,
        a.order_date ,
        a.style_number ,
        a.shipment_date ,
        X.*,
        b.country_name ,
        a.shipment_method_desc ,
        a.terms_desc
FROM    order_head a
        INNER JOIN order_address b ON a.order_id = b.order_id
                                      AND b.address_purpose = 'DE'
OUTER APPLY
(
SELECT packed_count = COUNT(order_id), packed_qty=SUM(packed_qty), gross_weight=SUM(gross_weight),