select a.id, a.name,b.time from (select id ,max(time) as time from b)b left join a on b.id = a.id join c on b.id = c.id
select a.id, a.name,b.time ,c.rscount from (select id ,max(time) as time from b)b left join a on b.id = a.id join c on b.id = c.id
--創建測試環境 Create Table a (ida varchar(11), nam varchar(31)) GO Insert a Select '1', '1' Union All Select '2', '1'GOCreate Table b (idb varchar(11), tim datetime) GO Insert b Select '1', '2007-07-01' Union All Select '1', '2007-07-02' Union All Select '1', '2007-08-03' Union All Select '2', '2007-03-03' Union All Select '2', '2007-03-04'GO Create Table c (idc varchar(11), rscount float) GO Insert c Select '1', 22 Union All Select '2', 22GOselect ida id ,nam name ,time = (select top 1 tim from b where idb = ida order by tim desc) ,rscount from a full join c on idc = ida
on b.id = a.id
join c on b.id = c.id
from (select id ,max(time) as time from b)b
left join a
on b.id = a.id
join c
on b.id = c.id
Create Table a
(ida varchar(11),
nam varchar(31))
GO
Insert a Select '1', '1'
Union All Select '2', '1'GOCreate Table b
(idb varchar(11),
tim datetime)
GO
Insert b Select '1', '2007-07-01'
Union All Select '1', '2007-07-02'
Union All Select '1', '2007-08-03'
Union All Select '2', '2007-03-03'
Union All Select '2', '2007-03-04'GO
Create Table c
(idc varchar(11),
rscount float)
GO
Insert c Select '1', 22
Union All Select '2', 22GOselect ida id ,nam name
,time = (select top 1 tim from b where idb = ida order by tim desc)
,rscount
from a full join c on idc = ida