尝试:
-- @tmp represents your table
declare @tmp table (
[Contract] int,
[Prices] decimal(18,5),
[ServiceDate] datetime
)
-- some testing data - you may skip that
insert into @tmp values(1, 100, '2011-01-01')
insert into @tmp values(1, 200, '2011-01-02')
insert into @tmp values(2, 10, '2011-01-01')
insert into @tmp values(2, 20, '2011-01-02')
insert into @tmp values(2, 30, '2011-01-03')
SELECT
[CONTRACT],
SUM(PRICES) as [TOTAL SPENT],
(SELECT TOP 1 t2.PRICES FROM @tmp t2
WHERE t2.[Contract] = t1.[Contract]
ORDER BY [SERVICEDATE]) as [FIRST PRICE]
FROM @tmp t1
GROUP BY [CONTRACT]
ORDER BY [CONTRACT]