--isnull(a.CpDate,b.LogDate)两个表时间数据 --isnull(a.CpCounts,0)第一个表的次数(假设) --isnull(b.LogCounts,0)第二个表的次数(假设) SELECT * FROM(select isnull(a.CpDate,b.LogDate) Dates,isnull(a.CpCounts,0) CpCount,isnull(b.LogCounts,0) LogCount from (SELECT CONVERT(NVARCHAR(7),createtime,120) CpDate, COUNT(*) CpCounts FROM dbo.CSP_ComponenetVersion GROUP BY CONVERT(NVARCHAR(7),createtime,120)) A FULL JOIN (SELECT CONVERT(NVARCHAR(7),QuoteTime,120) LogDate,SUM(ReferCount) LogCounts FROM dbo.CSP_ReferLog GROUP BY CONVERT(NVARCHAR(7),QuoteTime,120)) b on a.CpDate=b.LogDate) t WHERE t.Dates >=CONVERT(NVARCHAR(7),dateadd(month,-12,getdate()),120)