Для SQL Server версии 2005+ используйте запрос ниже, если вам нужен только столбец с флажком
--suppose this is your table
DECLARE @Table TABLE
(
ID int,gift_date datetime,gift_amt int
)
INSERT INTO @Table
SELECT 1,'1/6/09',500 UNION ALL
SELECT 2,'1/9/09',200 UNION ALL
SELECT 2,'1/15/09',65 UNION ALL
SELECT 3,'1/26/09',140 UNION ALL
SELECT 2,'2/10/09',600 UNION ALL
SELECT 3,'3/7/09',200
;WITH CTE As
(
SELECT ID,gift_date,gift_amt,
SUM(gift_amt)OVER(PARTITION BY ID) As TotalSum
FROM @Table
)
SELECT ID,gift_date,gift_amt,
CASE WHEN TotalSum>500 then 1 else 0 end as Flag
FROM CTE