使用 SQL Server 2005,我正在尝试编写一个 select 语句,它将查询下面的数据(18000 行)并为每个产品返回一行,找到最大的产品版本。
我认为查询需要反向比较版本,并在达到 Major 时存储最大的行号,但我不确定。
样本数据
Product Date Major Minor Release Fixpack Build
======= ========== ====== ====== ====== ====== ======
Widgets 01/01/2012 10 1 0 345 132
Widgets 04/02/2011 6 6 3 932 245
Widgets 09/01/2010 4 92 345 53 2
Gears 03/17/2011 9 2 3 0 21
Gears 12/12/2012 10 0 0 5 548
Tires 04/24/2000 8 3 456 3 984
Tires 04/12/1993 7 14 45 35 252
预期成绩
Product Date Major Minor Release Fixpack Build
======= ========== ====== ====== ====== ====== ======
Widgets 01/01/2012 10 1 0 345 132
Gears 12/12/2012 10 0 0 5 548
Tires 04/24/2000 8 3 456 3 984
或者甚至更好,可以将版本合并为一列:
Product Date ProductVersion
======= ========== ==================
Widgets 01/01/2012 10.1.0.345.132
Gears 12/12/2012 10.0.0.5.548
Tires 04/24/2000 8.3.456.3.984