기존 쿼리에 2 개의 새로운 열을 추가하고 싶습니다. 첫 번째에서는 현재 행과 다음 행 사이의 차이를 만들어 행 사이의 값을 계산합니다.행간 차이점
나의 현재 쿼리는 다음과 같습니다
SELECT *, SUM(MINUTE(rest_time)) AS Times
FROM routes as routes
LEFT JOIN sales
ON (routes.departure_poi_code = sales.client_code AND
routes.departure_date = sales.`date`)
WHERE (routes.departure_poi_code LIKE 'C0%' OR routes.departure_poi_code LIKE 'MP%')
AND routes.`car_no` = 'BH-07-EWR'
AND routes.departure_date = '2011-10-14'
GROUP BY routes.departure_address, reports.routes.departure_poi_code,
reports.routes.car_no, reports.routes.departure_date
ORDER BY routes.car_no
LIMIT 500000
내 현재 쿼리의 결과는 무엇인가 같다 : 더 열을 포함하지만 여기에 그들 모두를 표시 무관 물론
Car_Numbr Str_time Cod_nr KM
BH-07-EWR 08:59:00 C00425 7000
BH-07-EWR 10:29:00 C00149 8500
BH-07-EWR 14:27:00 C01075 9200
BH-07-EWR 15:07:00 C00305 9800
BH-07-EWR 16:08:00 C02572 9900
.
이야기는 차가 클라이언트 1에서 클라이언트 2까지 row2.km-row1.km를 만드는 것입니다. 물론 km km는 선상에 있습니다. 그리고 내가 좋아하는 것이 될 수 있습니다 :
Car_Number Start_time Code_nr KM Total_km Diff_km
BH-07-EWR 08:59:00 C00425 7000 0 (km counter starting from 0) 0 (first row show have 0)
BH-07-EWR 10:29:00 C00149 8500 1500 (0+8500-7000) 1500 (8500-7000)
BH-07-EWR 14:27:00 C01075 9200 2200 (upper result+9200-8500) 700 (9200-8500)
BH-07-EWR 15:07:00 C00305 9800 2800 (upper result+9800-9200) 600 (9800-9200)
BH-07-EWR 16:08:00 C02572 9900 2900 (upper result+9900-9800) 100 (9900-9800)
하는 방법이 가장 쉬운 방법은 달성 할 수 있습니까?
확인이 : http://stackoverflow.com/questions/5402938/mysql-find-difference-between-the-same-table – Sterex