日期:2014-05-17 浏览次数:20729 次
declare @StartDate varchar(20) --这个外面传进来的值。
select ID,SchoolID,FirstDate,TotalMoney
from
(
select ID,SchoolID,FristDate from table1
) a
LEFT JOIN
(
select SchoolID,sum(TotalMoney) as TotalMoney from talbe2
where YearMonthDay between a.FristDate between @StartDate
) b on a.SchoolID=b.SchoolID
declare @StartDate varchar(20) --这个外面传进来的值。
select ID,SchoolID,FirstDate,(select sum(TotalMoney) as TotalMoney from talbe2 b where a.SchoolID=b.SchoolID and YearMonthDay between a.FristDate between @StartDate ) TotalMoney
from table1 a
--表ta(date) tb(date)
select *
from ta
where date in (select date from tb group by date)
select *
from ta a
where exists (select 1 from tb where a.date = date)
select a.*
from ta a join tb b on a.date = b.date
-- ...
declare @StartDate varchar(20) --这个外面传进来的值。
SELECT A1.ID,
A1.SchoolID,
A1.FirstDate,
B1.TotalMoney
FROM table1 AS A1 WITH(NOLOCK) LEFT JOIN
(
SELECT B.SchoolID,
SUM(B.TotalMoney) AS TotalMoney
FROM table1 AS A WITH(NOLOCK) INNER JOIN
table2 AS B WITH(NOLOCK) ON A.SchoolID=A.SchoolID
WHERE B.YearMonthDay BETWEEN A.FristDate
AND CAST(@StartDate AS DATETIME)
GROUP BY B.SchoolID
) AS B1 ON A1.SchoolID=B1.SchoolID