在SQL Server中,我总是很难获得数据集的最大行数,我正在寻找一种方法列表,以获取有关性能和可维护性的一些指导来检索最大行数。
样品表:
DECLARE @Test TABLE (ID INT IDENTITY(1,1), name VARCHAR(50),
dateOfBirth DATETIME, TaxNumber varchar(10))
INSERT INTO @Test (name, dateOfBirth, TaxNumber)
SELECT 'Fred', convert(datetime, '25/01/1976', 103), '123' UNION ALL
SELECT 'Bob', convert(datetime, '03/03/1976', 103), '234' UNION ALL
SELECT 'Jane', convert(datetime, '13/06/1996', 103), '345' UNION ALL
SELECT 'Fred', convert(datetime, '14/02/1982', 103), '456' UNION ALL
SELECT 'Bob', convert(datetime, '25/10/1983', 103), '567' UNION ALL
SELECT 'Jane', convert(datetime, '12/04/1995', 103), '678' UNION ALL
SELECT 'Fred', convert(datetime, '03/03/1976', 103), '789'
select * from @Test
给出:
ID name dateOfBirth TaxNumber
----------- --------- ----------------------- ----------
1 Fred 1976-01-25 00:00:00.000 123
2 Bob 1976-03-03 00:00:00.000 234
3 Jane 1996-06-13 00:00:00.000 345
4 Fred 1982-02-14 00:00:00.000 456
5 Bob 1983-10-25 00:00:00.000 567
6 Jane 1995-04-12 00:00:00.000 678
7 Fred 1976-03-03 00:00:00.000 789
如果要检索最早的人(按姓名分组)的完整详细信息,我可以使用哪些方法?
所需的输出:
ID name dateOfBirth TaxNumber
----------- --------- ----------------------- ----------
1 Fred 1976-01-25 00:00:00.000 123
2 Bob 1976-03-03 00:00:00.000 234
6 Jane 1995-04-12 00:00:00.000 678