AssetID mileage Hrs sertype Covered Mileg
LF-310 1000 200 F1
LF-310 2000 400 F2
LF-311 1500 150 F1
LF-311 3000 300 F2
可以帮助一些人。如何计算最后的里程数。
答案 0 :(得分:0)
如果我能正确理解您的问题,此查询可以解决您的问题:
--DROP TABLE WORK_SHOP
Create Table WORK_SHOP
(
AssetID VARCHAR(10),
mileage int,
Hrs int,
sertype char(2)
)
INSERT INTO WORK_SHOP
VALUES('LF-310', 1000, 200 ,'F1'),
('LF-310', 2000, 400 ,'F2'),
('LF-311', 1500, 150 ,'F1'),
('LF-311', 3000, 300 ,'F2')
SELECT *
FROM(
SELECT AssetID,mileage,Hrs,sertype,
ROW_NUMBER() OVER (PARTITION BY AssetID
order by mileage) AS ROW_NUMBER
FROM WORK_SHOP) AS A
WHERE A.ROW_NUMBER =1