联立表查询

  • Post author:
  • Post category:其他


SELECT TW.ID,TC.MYUSERID,TW.DesIns,TC.MYDATE,TC.MYSTATUS FROM T_CLIENTINFO TW INNER JOIN (

select TA.id,(select top 1 CREATEDATE from T_SchoolFollow  WHERE CLIENTID=TA.ID

order by createdate desc) AS MYDATE,(select top 1 STATUS from T_SchoolFollow  WHERE CLIENTID=TA.ID

order by createdate desc) AS MYSTATUS,(select top 1 USERID from T_SchoolFollow  WHERE CLIENTID=TA.ID

order by createdate desc) AS MYUSERID FROM T_ClientInfo  TA ) TC ON TW.ID=TC.ID WHERE TC.MYDATE IS NOT NULL AND TC.MYSTATUS IS NOT NULL

AND  TC.MYDATE>=’2009-1-1 00:00:00′  AND TC.MYUSERID=45 ORDER BY TW.ID

转载于:https://www.cnblogs.com/hqbird/archive/2009/04/01/1427335.html