我想计算属于一个类别的所有记录并获取与最新记录关联的数据
CREATE TABLE #TestTable
(
SomeColumn VARCHAR(1)
,data varchar(50)
,CDate datetime
)
GO
INSERT INTO #TestTable VALUES ('A','abdss',getdate())
INSERT INTO #TestTable VALUES ('A','abserts',getdate())
INSERT INTO #TestTable VALUES ('A','awabs',getdate())
INSERT INTO #TestTable VALUES ('A','abrfgts',getdate())
INSERT INTO #TestTable VALUES ('A','abasds',getdate())
INSERT INTO #TestTable VALUES ('A','abasds',getdate())
INSERT INTO #TestTable VALUES ('A','aberzsdsfs',getdate())
INSERT INTO #TestTable VALUES ('A','abarfzdfs',getdate())
INSERT INTO #TestTable VALUES ('B','abzdsfs',getdate())
--SELECT * , COUNT(SomeColumn) From #TestTable
--GROUP BY SomeColumn
drop table #TestTable
所需的输出将是
SomeColumn | Data | Date |Other Associates Records <br/>
A | abarfzdfs |last A record date |7<br/>
B | abzdsfs |last B record date |0<br/>