我有一組關於麪包車(序列號,工作號,工作類型和當前里程)的記錄。SQL顯示記錄發生在字段中某個特定日期類型的最新信息後
select serial_number, call_ref, call_type_description, callm_data19
from calls
left join equipment on link_to_equipment=equipment_code
inner join lu_call_types on call_type=call_type_code
left join call_more on call_ref=callm_link_to_call
where serial_number = 'SH12ZLN'
order by call_ref desc
我希望能夠顯示在最近的「麪包車服務」記錄後發生的下一個「麪包車檢查」記錄。
這裏是數據
SH12ZLN 3023152 Van Inspection 83980
SH12ZLN 3019319 Van Inspection 83046
SH12ZLN 3016999 Van Servicing NULL
SH12ZLN 3016346 Van Inspection 81818
SH12ZLN 3012977 Van Inspection 80742
SH12ZLN 3010435 Van Inspection 79909
SH12ZLN 3008528 Van Repairs NULL
SH12ZLN 3006880 Van Inspection 78577
SH12ZLN 3001942 Van Inspection 76974
SH12ZLN 2998209 Van Inspection 75976
SH12ZLN 2994475 Van Inspection 75285
SH12ZLN 2991756 Van Repairs NULL
SH12ZLN 2989642 Van Inspection 74408
SH12ZLN 2985795 Van Inspection 73642
SH12ZLN 2981952 Van Inspection 72838
SH12ZLN 2978257 Van Inspection 72011
SH12ZLN 2975667 Van Inspection 70692
SH12ZLN 2972244 Van Inspection 69732
SH12ZLN 2969157 Van Inspection 68821
SH12ZLN 2959335 Van Inspection 67891
SH12ZLN 2956295 Van Inspection 66994
SH12ZLN 2948516 Van Inspection 66481
SH12ZLN 2946213 Van Inspection 65778
SH12ZLN 2939497 Van Inspection 64408
SH12ZLN 2937538 Van Inspection 63765
SH12ZLN 2934421 Van Inspection 62937
SH12ZLN 2932707 Van Inspection 61645
SH12ZLN 2930711 Van Inspection 60713
SH12ZLN 2930023 Van Inspection 59683
SH12ZLN 2924989 Van Inspection 58372
SH12ZLN 2924830 Van Repairs NULL
SH12ZLN 2922412 Van Inspection 57474
SH12ZLN 2919005 Van Servicing NULL
SH12ZLN 2918376 Van Repairs NULL
澄清的快照 - 我希望它只能產生以下記錄
SH12ZLN 3019319 Van Inspection 83046
請在13個帖子後學會格式化您的問題 – 2015-01-21 10:11:05
我剛剛在編輯過程中糾正格式,當你這樣做。 – chenks 2015-01-21 10:11:49
請在將來發布之前進行。您可以在編輯器下方的預覽中看到它的外觀。 – 2015-01-21 10:17:51