2017-04-11 36 views
0
  Hi i want to write the below query in different way can you please 

告訴我如何以不同方式寫入,因此最少需要 才能執行。不使用index.I書面查詢越來越精確的輸出,但它需要太多的時間優化查詢而不使用不在子句中

select distinct location from get_shipping_data gsd 
where location not in 

(
select pkd.shipmentlocation from package p 
left join packagedetail pkd on pkd.packingid=p.packingid 
where p.shippingnum='SH0667075' 

) 
and gsd.shipmentid='SH0667075' 
+0

如果您粘貼查詢和所需輸出的*文本*而不是圖像,它將會更有用。其次,如果查詢正在運行,您應該在[CodeReview](http://codereview.stackexchange.com/)上發佈。你使用的是 – trincot

+0

應該在1行中返回兩個結果嗎?使用STUFF – maSTAShuFu

回答

0

有沒有除了這裏建議多,沒有索引可以使用寫你的查詢聯接:

select distinct location 
    from get_shipping_data gsd 
     inner join 
     (select p.shippingnum, pkd.shipmentlocation 
      from package p 
       left join packagedetail pkd 
       on pkd.packingid=p.packingid 
     where p.shippingnum='SH0667075') ps 
     ON gsd.location = ps.shipmentlocation 
      AND gsd.shipmentid = ps.shippingnum 
where ps.shipmentlocation is null 
    AND gsd.shipmentid='SH0667075' 

嘗試它,看看它是否給你任何改善。

+0

感謝它給出了更好的性能 –

+0

輸出沒有得到正確 –

+0

怎麼會這樣?你可以解釋嗎? –