sql多表联查四种方法

发布时间:2020-05-22编辑:脚本学堂
本文介绍了sql多表联查的四种方法与实例代码,有需要的朋友参考下。

本节内容:
sql多表联查实例

介绍四个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)

sql多表联查,方法二:
 

复制代码 代码示例:
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

sql多表联查,方法三
 

复制代码 代码示例:
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)

sql多表联查,方法四
 

复制代码 代码示例:
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