程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> sql多表聯查實例

sql多表聯查實例

編輯:MySQL綜合教程

   sql多表聯查實例

  下面提供四款sql多表關聯查詢的實例,個個效率不一樣。

  select * from order_info as a ,ivrlog4ivrdlvinst as b

  where

  (a.saleorder=b.ext1_skill and b.start_date=@date1 and se_id='55' and b.ext1_skill!='')

  and convert(varchar(10),a.instime,112)=@date2 and max(a.instime)

  方法二

  select * from order_info as a

  where a.saleorder=(

  select b.ext1_skill from ivrlog4ivrdlvinst as b

  where b.start_date=@date1 and se_id='55'

  and b.ext1_skill!='')

  and convert(varchar(10),max(a.instime),112)=@date2

  方法三

  declare

  @date1 varchar(20),

  @date2 varchar(20)

  set @date1='20100812'

  set @date2='2010-08-12'

  select * from order_info as a

  where a.saleorder=

  (select b.ext1_skill from ivrlog4ivrdlvinst as b where b.start_date=@date1 and se_id='55' and b.ext1_skill!='')

  and convert(varchar(10),a.instime,112)=@date2

  and max(a.instime)

  方法四

  select b.caller, b.start_date, b.start_time, b.ext1_skill,

  c.deliveryno, c.destroyresult, c.deliverydate, c.deliverytime, c.arrangetime, c.driverphone, c.drivermobile,

  a.servicedate, a.servicetime, a.workertel

  from order_info as a ,ivrlog4ivrdlvinst as b ,delivery_info as c

  where

  a.saleorder in (select b.ext1_skill from ivrlog4ivrdlvinst where b.start_date=@date1 and b.se_id='55' and b.ext1_skill!='')

  and convert(varchar(10),a.instime,112)=@date2

  order by b.start_date desc, b.start_time desc

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved