Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
using lead() and sum() with over() in mssql
--Sql Server 2014 Express Edition --Batches are separated by 'go' declare @fuel_transaction table ([meter] int, [payment_type] varchar(4), [cost_per_unit] numeric, [total_units] numeric, [pump_id] varchar(4), [ac_id] varchar(8), [fuel_type_id] varchar(3), [units] varchar(4), [cost_total] int, [comments] varchar(62), [vehicle_id] int, [date_trans] datetime, [time_trans] datetime) ; INSERT INTO @fuel_transaction ([meter], [payment_type], [cost_per_unit], [total_units], [pump_id], [ac_id], [fuel_type_id], [units], [cost_total], [comments], [vehicle_id], [date_trans], [time_trans]) VALUES (68797, NULL, 1.92, 34.43, NULL, '53010108', 'GAS', NULL, 34.43, NULL, 1109, '2016-01-06 00:00:00', '1899-12-30 02:41:00'), (68984, NULL, 1.73, 17.3, NULL, '53010108', 'GAS', NULL, 29.91, NULL, 1109, '2016-01-13 00:00:00', '1899-12-30 11:43:00'), (69209, NULL, 1.68, 22, NULL, '53010108', 'GAS', NULL, 36.94, NULL, 1109, '2016-01-26 00:00:00', '1899-12-30 12:01:00'), (69382, NULL, 1.66, 13.26, NULL, '53010108', 'GAS', NULL, 22, NULL, 1109, '2016-01-29 00:00:00', '1899-12-30 12:33:00'), (69525, NULL, 1.6, 14.42, NULL, '53010108', 'GAS', NULL, 23.06, NULL, 1109, '2016-02-04 00:00:00', '1899-12-30 16:13:00'), (69691, NULL, 1.5, 16.15, NULL, '53010108', 'GAS', NULL, 24.21, NULL, 1109, '2016-02-12 00:00:00', '1899-12-30 12:25:00'), (69843, NULL, 1.5, 14.962, NULL, '53010108', 'GAS', NULL, 22.43, NULL, 1109, '2016-02-23 00:00:00', '1899-12-30 07:41:00'), (70232, NULL, 1.76, 12.35, NULL, '53010108', 'GAS', NULL, 21.72, NULL, 1109, '2016-03-01 00:00:00', '1899-12-30 19:15:00'), (70428, NULL, 1.76, 17.29, NULL, '53010108', 'GAS', NULL, 30.41, NULL, 1109, '2016-03-07 00:00:00', '1899-12-30 09:51:00'), (70685, NULL, 1.97, 22.56, NULL, '53010108', 'GAS', NULL, 44.41, NULL, 1109, '2016-03-23 00:00:00', '1899-12-30 10:03:00'), (70840, NULL, 1.97, 13.56, NULL, '53010108', 'GAS', NULL, 26.71, NULL, 1109, '2016-03-29 00:00:00', '1899-12-30 06:28:00'), (71253, NULL, 1.9, 19.67, NULL, '53010108', 'GAS', NULL, 37.35, NULL, 1109, '2016-04-03 00:00:00', '1899-12-30 18:28:00'), (71469, NULL, 1.95, 18.24, NULL, '53010108', 'GAS', NULL, 35.55, NULL, 1109, '2016-04-12 00:00:00', '1899-12-30 15:47:00'), (71756, NULL, 2.17, 25.09, NULL, '53010108', 'GAS', NULL, 54.43, NULL, 1109, '2016-04-17 00:00:00', '1899-12-30 15:38:00'), (72007, NULL, 2.12, 17.03, NULL, '53010108', 'GAS', NULL, 36.1, NULL, 1109, '2016-04-22 00:00:00', '1899-12-30 11:02:37'), (72266, NULL, 2.21, 18.03, NULL, '53010108', 'GAS', NULL, 39.84, NULL, 1109, '2016-04-29 00:00:00', '1899-12-30 11:09:30'), (72348, NULL, 1.97, 27.19, NULL, '53010108', 'GAS', NULL, 53.54, NULL, 1109, '2016-05-05 00:00:00', '1899-12-30 16:03:00'), (72623, NULL, 2.13, 24.5, NULL, '53010108', 'GAS', NULL, 52.15, NULL, 1109, '2016-05-17 00:00:00', '1899-12-30 05:26:00'), (72748, NULL, 2.13, 9.08, NULL, '53010108', 'GAS', NULL, 19.34, NULL, 1109, '2016-05-21 00:00:00', '1899-12-30 10:23:09'), (73040, NULL, 2.2, 24.28, NULL, '53010108', 'GAS', NULL, 53.38, NULL, 1109, '2016-06-01 00:00:00', '1899-12-30 16:38:00'), (73201, NULL, 2.18, 14.88, NULL, '53010108', 'GAS', NULL, 32.41, NULL, 1109, '2016-06-14 00:00:00', '1899-12-30 18:09:00'), (73379, NULL, 2.34, 17.17, NULL, '53010108', 'GAS', NULL, 40.15, NULL, 1109, '2016-06-24 00:00:00', '1899-12-30 07:49:46'), (73716, NULL, 2.15, 28.08, NULL, '53010108', 'GAS', NULL, 60.34, NULL, 1109, '2016-06-28 00:00:00', '1899-12-30 14:33:00'), (73873, NULL, 2.08, 14.33, NULL, '53010108', 'GAS', NULL, 29.79, NULL, 1109, '2016-07-11 00:00:00', '1899-12-30 12:01:00'), (74180, NULL, 2.1, 25.42, NULL, '53010108', 'GAS', NULL, 53.38, NULL, 1109, '2016-07-13 00:00:00', '1899-12-30 07:09:00'), (74458, NULL, 2.06, 23.29, NULL, '53010108', 'GAS', NULL, 47.96, NULL, 1109, '2016-07-18 00:00:00', '1899-12-30 13:07:00'), (74650, NULL, 2.08, 15.9, NULL, '53010108', 'GAS', NULL, 33.07, NULL, 1109, '2016-07-19 00:00:00', '1899-12-30 13:49:00'), (74833, NULL, 2, 5.02, NULL, '53010108', 'GAS', NULL, 10.03, NULL, 1109, '2016-07-26 00:00:00', '1899-12-30 06:25:00'), (74834, NULL, 2, 12.3, NULL, '53010108', 'GAS', NULL, 24.59, NULL, 1109, '2016-07-26 00:00:00', '1899-12-30 06:29:00'), (75058, NULL, 2, 24.18, NULL, '53010108', 'GAS', NULL, 48.36, NULL, 1109, '2016-07-29 00:00:00', '1899-12-30 22:04:00'), (75260, NULL, 2, 20.25, NULL, '53010108', 'GAS', NULL, 48.49, NULL, 1109, '2016-08-06 00:00:00', '1899-12-30 06:52:00'), (75449, NULL, 2.13, 13.09, NULL, '53010108', 'GAS', NULL, 27.88, NULL, 1109, '2016-08-08 00:00:00', '1899-12-30 13:43:00'), (76609, NULL, 2.1, 13.27, NULL, '53010108', 'GAS', NULL, 27.85, NULL, 1109, '2016-08-10 00:00:00', '1899-12-30 14:32:00'), (75825, NULL, 2.33, 20.92, NULL, '53010108', 'GAS', NULL, 48.72, NULL, 1109, '2016-08-19 00:00:00', '1899-12-30 11:00:00'), (76097, NULL, 2.15, 22.8, NULL, '53010108', 'GAS', NULL, 49.01, NULL, 1109, '2016-08-31 00:00:00', '1899-12-30 11:13:00'), (76283, NULL, 1.98, 16.34, NULL, '53010108', 'GAS', NULL, 32.34, NULL, 1109, '2016-09-10 00:00:00', '1899-12-30 21:37:00'), (76539, NULL, 2.18, 21.55, NULL, '53010108', 'GAS', NULL, 46.97, NULL, 1109, '2016-09-13 00:00:00', '1899-12-30 12:36:00'), (76747, NULL, 1.96, 16.97, NULL, '53010108', 'GAS', NULL, 33.25, NULL, 1109, '2016-09-19 00:00:00', '1899-12-30 13:16:00'), (76894, NULL, 2.06, 12.7, NULL, '53010108', 'GAS', NULL, 26.16, NULL, 1109, '2016-09-23 00:00:00', '1899-12-30 11:58:00'), (77180, NULL, 2.42, 25.53, NULL, '53010108', 'GAS', NULL, 61.76, NULL, 1109, '2016-10-07 00:00:00', '1899-12-30 14:21:00'), (77473, NULL, 2.1, 22.3, NULL, '53010108', 'GAS', NULL, 46.82, NULL, 1109, '2016-10-14 00:00:00', '1899-12-30 06:35:05'), (77656, NULL, 2.12, 16, NULL, '53010108', 'GAS', NULL, 33.88, NULL, 1109, '2016-10-24 00:00:00', '1899-12-30 10:13:00'), (77890, NULL, 2.1, 19.94, NULL, '53010108', 'GAS', NULL, 41.85, NULL, 1109, '2016-11-01 00:00:00', '1899-12-30 14:39:00'), (78049, NULL, 1.98, 14.6, NULL, '53010108', 'GAS', NULL, 28.93, NULL, 1109, '2016-11-15 00:00:00', '1899-12-30 15:09:00'), (10198, NULL, 3.29, 21.55, NULL, '53010110', 'GAS', NULL, 71.12, NULL, 1110, '2012-06-07 00:00:00', '1899-12-30 13:27:07'), (10353, NULL, 3.57, 21.661, NULL, '53010108', 'GAS', NULL, 77.52, NULL, 1110, '2012-06-25 00:00:00', '1899-12-30 07:35:00'), (10785, NULL, 3.48, 24.6, NULL, '53010108', 'GAS', NULL, 85.83, NULL, 1110, '2012-07-04 00:00:00', '1899-12-30 07:37:00'), (11055, NULL, 3.39, 22.83, NULL, '53010108', 'GAS', NULL, 77.6, NULL, 1110, '2012-07-20 00:00:00', '1899-12-30 14:37:00'), (11440, NULL, 3.42, 25.64, NULL, '53010108', 'GAS', NULL, 87.92, NULL, 1110, '2012-07-27 00:00:00', '1899-12-30 08:07:59'), (11673, NULL, 3.65, 23.13, NULL, '53010108', 'GAS', NULL, 84.66, NULL, 1110, '2012-08-09 00:00:00', '1899-12-30 09:34:52'), (11903, NULL, 3.65, 22.9, NULL, '53010108', 'GAS', NULL, 83.86, NULL, 1110, '2012-08-21 00:00:00', '1899-12-30 07:04:00'), (13032, NULL, 3.72, 24.42, NULL, '53010108', 'GAS', NULL, 91.07, 'omaha trip', 1110, '2012-09-27 00:00:00', '1899-12-30 09:22:31'), (13850, NULL, 2.99, 23.5, NULL, '53010108', 'GAS', NULL, 70.5, 'Dummy entry to true up the data', 1110, '2012-12-24 00:00:00', '1899-12-30 11:28:33'), (14683, NULL, 3.46, 21.57, NULL, '53010108', 'GAS', NULL, 75.03, 'Dummy entry to true up the data', 1110, '2013-01-01 00:00:00', '1899-12-30 12:00:42'), (14913, NULL, 2.99, 23.5, NULL, '53010108', 'GAS', NULL, 70.5, NULL, 1110, '2013-01-09 00:00:00', '1899-12-30 10:23:31'), (15113, NULL, 3.16, 16.25, NULL, '53010108', 'GAS', NULL, 51.52, NULL, 1110, '2013-01-26 00:00:00', '1899-12-30 09:23:00'), (15337, NULL, 3.77, 19.06, NULL, '53010108', 'GAS', NULL, 72.04, NULL, 1110, '2013-02-18 00:00:00', '1899-12-30 07:16:00'), (15545, NULL, 3.67, 21.31, NULL, '53010108', 'GAS', NULL, 78.43, NULL, 1110, '2013-03-05 00:00:00', '1899-12-30 09:06:00'), (15763, NULL, 3.47, 20.52, NULL, '53010108', 'GAS', NULL, 71.42, NULL, 1110, '2013-03-21 00:00:00', '1899-12-30 08:57:00'), (16015, NULL, 3.47, 22.16, NULL, '53010108', 'GAS', NULL, 77.1, NULL, 1110, '2013-04-04 00:00:00', '1899-12-30 08:19:00'), (16201, NULL, 3.27, 22.41, NULL, '53010108', 'GAS', NULL, 73.5, NULL, 1110, '2013-04-19 00:00:00', '1899-12-30 08:24:00'), (16573, NULL, 3.47, 23.63, NULL, '53010108', 'GAS', NULL, 82.21, NULL, 1110, '2013-05-06 00:00:00', '1899-12-30 07:12:00'), (16896, NULL, 3.89, 25.28, NULL, '53010108', 'GAS', NULL, 98.59, NULL, 1110, '2013-05-16 00:00:00', '1899-12-30 11:16:00'), (17206, NULL, 3.69, 23.98, NULL, '53010108', 'GAS', NULL, 88.71, NULL, 1110, '2013-05-31 00:00:00', '1899-12-30 12:58:00'), (17482, NULL, 3.54, 21.66, NULL, '53010108', 'GAS', NULL, 76.9, NULL, 1110, '2013-06-17 00:00:00', '1899-12-30 06:20:00'), (17767, NULL, 3.56, 22.8, NULL, '53010108', 'GAS', NULL, 81.46, NULL, 1110, '2013-07-15 00:00:00', '1899-12-30 09:18:00'), (18061, NULL, 3.65, 24.89, NULL, '53010108', 'GAS', NULL, 91.08, NULL, 1110, '2013-07-29 00:00:00', '1899-12-30 12:18:00'), (18339, NULL, 3.59, 23.24, NULL, '53010108', 'GAS', NULL, 83.67, NULL, 1110, '2013-08-08 00:00:00', '1899-12-30 12:25:00'), (18546, NULL, 3.57, 16.59, NULL, '53010108', 'GAS', NULL, 59.39, NULL, 1110, '2013-08-21 00:00:00', '1899-12-30 12:16:00'), (18856, NULL, 3.62, 24.65, NULL, '53010108', 'GAS', NULL, 89.48, NULL, 1110, '2013-09-06 00:00:00', '1899-12-30 11:13:00'), (19136, NULL, 3.52, 23.2, NULL, '53010108', 'GAS', NULL, 81.98, NULL, 1110, '2013-09-18 00:00:00', '1899-12-30 11:08:00'), (19568, NULL, 3.05, 8.6, NULL, '53010108', 'GAS', NULL, 26.33, NULL, 1110, '2013-10-21 00:00:00', '1899-12-30 13:24:00'), (19785, NULL, 3.22, 19.7, NULL, '53010108', 'GAS', NULL, 63.87, 'trip to Omaha for Ariba Training', 1110, '2013-10-23 00:00:00', '1899-12-30 11:07:00'), (20421, NULL, 2.97, 25.81, NULL, '53010108', 'GAS', NULL, 76.89, NULL, 1110, '2013-11-15 00:00:00', '1899-12-30 06:24:00'), (20674, NULL, 2.95, 22.68, NULL, '53010108', 'GAS', NULL, 67.12, NULL, 1110, '2013-12-03 00:00:00', '1899-12-30 10:50:00'), (20943, NULL, 2.92, 24.36, NULL, '53010108', 'GAS', NULL, 71.35, NULL, 1110, '2013-12-13 00:00:00', '1899-12-30 10:20:00'), (21190, NULL, 3.07, 22.2, NULL, '53010108', 'GAS', NULL, 68.44, NULL, 1110, '2014-01-03 00:00:00', '1899-12-30 07:33:00'), (21413, NULL, 3.13, 22.65, NULL, '53010108', 'GAS', NULL, 71.11, NULL, 1110, '2014-01-20 00:00:00', '1899-12-30 11:27:00'), (21646, NULL, 3.09, 21.7, NULL, '53010108', 'GAS', NULL, 67.46, NULL, 1110, '2014-01-30 00:00:00', '1899-12-30 14:25:00'), (21702, NULL, 3.09, 10.38, NULL, '53010108', 'GAS', NULL, 32.18, NULL, 1110, '2014-02-04 00:00:00', '1899-12-30 09:38:00'), (21972, NULL, 3.36, 24, NULL, '53010108', 'GAS', NULL, 80.95, NULL, 1110, '2014-02-24 00:00:00', '1899-12-30 07:30:00'), (22481, NULL, 3.47, 22.6, NULL, '53010108', 'GAS', NULL, 78.69, NULL, 1110, '2014-03-28 00:00:00', '1899-12-30 09:00:00'), (23071, NULL, 3.52, 22.6, NULL, '53010108', 'GAS', NULL, 79.78, NULL, 1110, '2014-05-02 00:00:00', '1899-12-30 11:34:00'), (23389, NULL, 3.44, 24.4, NULL, '53010108', 'GAS', NULL, 84.17, NULL, 1110, '2014-05-13 00:00:00', '1899-12-30 13:46:00'), (23693, NULL, 3.62, 24.85, NULL, '53010108', 'GAS', NULL, 90.2, NULL, 1110, '2014-05-29 00:00:00', '1899-12-30 11:04:00'), (23957, NULL, 3.68, 21.5, NULL, '53010108', 'GAS', NULL, 79.22, NULL, 1110, '2014-06-17 00:00:00', '1899-12-30 10:32:00'), (24259, NULL, 3.62, 24.8, NULL, '53010108', 'GAS', NULL, 90.06, NULL, 1110, '2014-07-07 00:00:00', '1899-12-30 12:16:00'), (24538, NULL, 3.44, 23, NULL, '53010108', 'GAS', NULL, 79.5, NULL, 1110, '2014-07-24 00:00:00', '1899-12-30 11:20:00'), (25139, NULL, 3.32, 25.4, NULL, '53010108', 'GAS', NULL, 84.7, NULL, 1110, '2014-08-25 00:00:00', '1899-12-30 04:11:00'), (25426, NULL, 3.29, 15.7, NULL, '53010108', 'GAS', NULL, 51.83, 'omaha trip', 1110, '2014-08-27 00:00:00', '1899-12-30 03:55:00'), (25198, NULL, 3.32, 5.94, NULL, '53010108', 'GAS', NULL, 19.78, 'top off for Omaha trip ...training', 1110, '2014-08-27 00:00:00', '1899-12-30 07:14:00'), (25759, NULL, 3.29, 25.8, NULL, '53010108', 'GAS', NULL, 85.14, NULL, 1110, '2014-09-02 00:00:00', '1899-12-30 06:17:00'), (26067, NULL, 3.26, 25.7, NULL, '53010108', 'GAS', NULL, 84.24, NULL, 1110, '2014-09-18 00:00:00', '1899-12-30 06:45:00'), (26666, NULL, 2.94, 23.7, NULL, '53010108', 'GAS', NULL, 70, NULL, 1110, '2014-10-27 00:00:00', '1899-12-30 11:22:00'), (26924, NULL, 2.81, 22.7, NULL, '53010108', 'GAS', NULL, 64.12, NULL, 1110, '2014-11-12 00:00:00', '1899-12-30 08:22:00'), (27107, NULL, 2.69, 17.9, NULL, '53010108', 'GAS', NULL, 48.5, NULL, 1110, '2014-11-21 00:00:00', '1899-12-30 07:32:00'), (27373, NULL, 2.35, 25.36, NULL, '53010108', 'GAS', NULL, 59.82, NULL, 1110, '2014-12-12 00:00:00', '1899-12-30 06:32:00'), (27609, NULL, 1.99, 20.4, NULL, '53010108', 'GAS', NULL, 40.88, NULL, 1110, '2014-12-23 00:00:00', '1899-12-30 08:40:00'), (27839, NULL, 1.75, 23.8, NULL, '53010108', 'GAS', NULL, 41.94, NULL, 1110, '2015-01-19 00:00:00', '1899-12-30 07:18:00'), (28061, NULL, 1.96, 19.4, NULL, '53010108', 'GAS', NULL, 38.39, NULL, 1110, '2015-01-29 00:00:00', '1899-12-30 08:27:00'), (28366, NULL, 2.16, 4.84, NULL, '53010108', 'GAS', NULL, 10.5, NULL, 1110, '2015-02-16 00:00:00', '1899-12-30 09:53:00'), (28544, NULL, 2.34, 16.69, NULL, '53010108', 'GAS', NULL, 39.22, NULL, 1110, '2015-02-18 00:00:00', '1899-12-30 01:40:00'), (28890, NULL, 2.24, 24.83, NULL, '53010108', 'GAS', NULL, 55.85, NULL, 1110, '2015-02-25 00:00:00', '1899-12-30 14:03:00'), (29169, NULL, 2.34, 24.1, NULL, '53010108', 'GAS', NULL, 56.69, NULL, 1110, '2015-03-09 00:00:00', '1899-12-30 09:44:00'), (29459, NULL, 2.24, 23.56, NULL, '53010108', 'GAS', NULL, 53, NULL, 1110, '2015-03-26 00:00:00', '1899-12-30 07:52:00'), (29775, NULL, 2.26, 25.1, NULL, '53010108', 'GAS', NULL, 57, NULL, 1110, '2015-04-08 00:00:00', '1899-12-30 07:21:00'), (30371, NULL, 2.34, 23.29, NULL, '53010108', 'GAS', NULL, 54.73, NULL, 1110, '2015-04-30 00:00:00', '1899-12-30 06:35:00'), (30987, NULL, 2.65, 25.12, NULL, '53010108', 'GAS', NULL, 66.8, NULL, 1110, '2015-06-05 00:00:00', '1899-12-30 07:36:00'), (31306, NULL, 2.75, 25.5, NULL, '53010108', 'GAS', NULL, 70.62, NULL, 1110, '2015-06-16 00:00:00', '1899-12-30 08:40:00'), (31603, NULL, 2.63, 24.4, NULL, '53010108', 'GAS', NULL, 64.42, NULL, 1110, '2015-06-29 00:00:00', '1899-12-30 01:36:00'), (31914, NULL, 2.69, 25.4, NULL, '53010108', 'GAS', NULL, 68.59, NULL, 1110, '2015-07-10 00:00:00', '1899-12-30 08:16:00'), (32235, NULL, 2.77, 24.9, NULL, '53010108', 'GAS', NULL, 69.35, NULL, 1110, '2015-07-22 00:00:00', '1899-12-30 09:58:00'), (32527, NULL, 2.66, 23.3, NULL, '53010108', 'GAS', NULL, 62.22, 'their time is off by at least 30 min.', 1110, '2015-07-30 00:00:00', '1899-12-30 10:11:00'), (32832, NULL, 2.59, 24.9, NULL, '53010108', 'GAS', NULL, 64.91, NULL, 1110, '2015-08-12 00:00:00', '1899-12-30 06:54:00'), (33140, NULL, 2.57, 24.4, NULL, '53010108', 'GAS', NULL, 63.04, NULL, 1110, '2015-08-25 00:00:00', '1899-12-30 10:16:00'), (33452, NULL, 2.35, 25.05, NULL, '53010108', 'GAS', NULL, 59.11, NULL, 1110, '2015-09-09 00:00:00', '1899-12-30 10:21:00'), (33738, NULL, 2.19, 22.48, NULL, '53010108', 'GAS', NULL, 49.45, NULL, 1110, '2015-09-21 00:00:00', '1899-12-30 07:06:00'), (34053, NULL, 2.23, 25.12, NULL, '53010108', 'GAS', NULL, 56.26, NULL, 1110, '2015-10-01 00:00:00', '1899-12-30 11:03:00'), (34346, NULL, 2.29, 23.7, NULL, '53010108', 'GAS', NULL, 54.5, NULL, 1110, '2015-10-14 00:00:00', '1899-12-30 07:39:00'), (34563, NULL, 2.14, 17.9, NULL, '53010108', 'GAS', NULL, 38.47, NULL, 1110, '2015-10-29 00:00:00', '1899-12-30 05:56:00'), (34387, NULL, 2.16, 23.3, NULL, '53010108', 'GAS', NULL, 50.73, NULL, 1110, '2015-11-09 00:00:00', '1899-12-30 14:39:52'), (35158, NULL, 1.97, 25.7, NULL, '53010108', 'GAS', NULL, 50.95, NULL, 1110, '2015-11-20 00:00:00', '1899-12-30 06:28:00'), (35441, NULL, 1.85, 23.94, NULL, '53010108', 'GAS', NULL, 44.51, NULL, 1110, '2015-12-02 00:00:00', '1899-12-30 12:35:00'), (35742, NULL, 1.85, 25.14, NULL, '53010108', 'GAS', NULL, 46.74, NULL, 1110, '2015-12-11 00:00:00', '1899-12-30 12:07:00'), (35982, NULL, 1.77, 21.4, NULL, '53010108', 'GAS', NULL, 38.22, NULL, 1110, '2015-12-23 00:00:00', '1899-12-30 06:43:00'), (36075, NULL, 1.71, 9.49, NULL, '53010108', 'GAS', NULL, 16.32, NULL, 1110, '2015-12-29 00:00:00', '1899-12-30 07:16:00'), (36220, NULL, 1.79, 13.7, NULL, '53010108', 'GAS', NULL, 24.68, NULL, 1110, '2016-01-06 00:00:00', '1899-12-30 07:34:00'), (36406, NULL, 1.74, 15.7, NULL, '53010108', 'GAS', NULL, 27.52, NULL, 1110, '2016-01-13 00:00:00', '1899-12-30 06:56:00'), (36537, NULL, 1.67, 12.5, NULL, '53010108', 'GAS', NULL, 21, NULL, 1110, '2016-01-19 00:00:00', '1899-12-30 10:12:00'), (36826, NULL, 1.54, 24.5, NULL, '53010108', 'GAS', NULL, 38.09, 'time stamped on receipt isn''t correct , it was closer to 9 am', 1110, '2016-01-29 00:00:00', '1899-12-30 06:35:00'), (37109, NULL, 1.42, 24.5, NULL, '53010108', 'GAS', NULL, 35.11, NULL, 1110, '2016-02-11 00:00:00', '1899-12-30 13:13:00'), (37709, NULL, 1.77, 24, NULL, '53010108', 'GAS', NULL, 42.87, NULL, 1110, '2016-03-07 00:00:00', '1899-12-30 13:31:00'), (38018, NULL, 1.85, 25.4, NULL, '53010108', 'GAS', NULL, 47.28, NULL, 1110, '2016-03-18 00:00:00', '1899-12-30 13:27:00'), (38314, NULL, 1.93, 24.9, NULL, '53010108', 'GAS', NULL, 48.32, NULL, 1110, '2016-04-01 00:00:00', '1899-12-30 07:45:00'), (38622, NULL, 1.86, 25.1, NULL, '53010108', 'GAS', NULL, 47.02, NULL, 1110, '2016-04-11 00:00:00', '1899-12-30 15:10:00'), (38888, NULL, 2.05, 21.2, NULL, '53010108', 'GAS', NULL, 43.65, NULL, 1110, '2016-04-22 00:00:00', '1899-12-30 06:47:00'), (39220, NULL, 1.95, 26.08, NULL, '53010108', 'GAS', NULL, 51.11, NULL, 1110, '2016-05-03 00:00:00', '1899-12-30 14:35:00'), (39524, NULL, 1.93, 23.7, NULL, '53010108', 'GAS', NULL, 46.11, NULL, 1110, '2016-05-12 00:00:00', '1899-12-30 09:44:52'), (39805, NULL, 2.17, 23.1, NULL, '53010108', 'GAS', NULL, 50.42, NULL, 1110, '2016-05-23 00:00:00', '1899-12-30 07:08:00'), (40127, NULL, 2.24, 24.8, NULL, '53010108', 'GAS', NULL, 55.94, NULL, 1110, '2016-06-06 00:00:00', '1899-12-30 14:47:00'), (40428, NULL, 2.31, 24.3, NULL, '53010108', 'GAS', NULL, 56.43, NULL, 1110, '2016-06-17 00:00:00', '1899-12-30 07:08:00'), (40745, NULL, 2.23, 24.9, NULL, '53010108', 'GAS', NULL, 55.92, NULL, 1110, '2016-06-27 00:00:00', '1899-12-30 16:39:00'), (41003, NULL, 2.12, 22, NULL, '53010108', 'GAS', NULL, 47, NULL, 1110, '2016-07-11 00:00:00', '1899-12-30 07:12:00'), (41308, NULL, 2.03, 25.2, NULL, '53010108', 'GAS', NULL, 51.47, NULL, 1110, '2016-07-20 00:00:00', '1899-12-30 12:17:00'), (41620, NULL, 2.14, 25.35, NULL, '53010108', 'GAS', NULL, 54.49, NULL, 1110, '2016-08-02 00:00:00', '1899-12-30 06:04:00'), (41897, NULL, 2.21, 21.9, NULL, '53010108', 'GAS', NULL, 48.79, NULL, 1110, '2016-08-15 00:00:00', '1899-12-30 07:19:00'), (42202, NULL, 2.27, 25.5, NULL, '53010108', 'GAS', NULL, 58.33, NULL, 1110, '2016-08-29 00:00:00', '1899-12-30 13:30:00'), (42527, NULL, 2.17, 25.6, NULL, '53010108', 'GAS', NULL, 55.81, NULL, 1110, '2016-09-12 00:00:00', '1899-12-30 10:12:00'), (42829, NULL, 2.15, 24.2, NULL, '53010108', 'GAS', NULL, 52.26, NULL, 1110, '2016-09-21 00:00:00', '1899-12-30 09:21:00'), (43141, NULL, 2.18, 24.4, NULL, '53010108', 'GAS', NULL, 51.57, NULL, 1110, '2016-09-28 00:00:00', '1899-12-30 12:45:00'), (21000, NULL, 3.53, 23.738, NULL, NULL, 'GAS', NULL, 84.01, NULL, 1112, '2012-06-11 00:00:00', '1899-12-30 07:00:00'), (21419, NULL, 3.44, 26.675, NULL, '53010108', 'GAS', NULL, 92, NULL, 1112, '2012-06-28 00:00:00', '1899-12-30 07:16:03'), (21771, NULL, 3.59, 24.729, NULL, '53010108', 'GAS', NULL, 89, NULL, 1112, '2012-07-05 00:00:00', '1899-12-30 10:00:00'), (22093, NULL, 3.41, 22.082, NULL, '53010108', 'GAS', NULL, 75.5, NULL, 1112, '2012-07-11 00:00:00', '1899-12-30 06:00:00'), (22438, NULL, 3.39, 22.361, NULL, '53010108', 'GAS', NULL, 76.01, NULL, 1112, '2012-07-17 00:00:00', '1899-12-30 07:00:00'), (22825, NULL, 3.44, 27.833, NULL, '53010108', 'GAS', NULL, 96, NULL, 1112, '2012-07-20 00:00:00', '1899-12-30 14:57:00'), (23200, NULL, 3.36, 24.637, NULL, '53010108', 'GAS', NULL, 83, NULL, 1112, '2012-07-26 00:00:00', '1899-12-30 05:44:00'), (23570, NULL, 3.53, 25.996, NULL, '53010108', 'GAS', NULL, 92, NULL, 1112, '2012-08-02 00:00:00', '1899-12-30 07:00:00'), (23928, NULL, 3.85, 24.877, NULL, '53010108', 'GAS', NULL, 96, NULL, 1112, '2012-08-08 00:00:00', '1899-12-30 01:00:00'), (24285, NULL, 3.83, 24.225, NULL, '53010108', 'GAS', NULL, 93, NULL, 1112, '2012-08-16 00:00:00', '1899-12-30 07:50:00'), (24654, NULL, 3.77, 24.346, NULL, '53010108', 'GAS', NULL, 92, NULL, 1112, '2012-08-24 00:00:00', '1899-12-30 05:47:00'), (25035, NULL, 3.93, 25.386, NULL, '53010108', 'GAS', NULL, 100, NULL, 1112, '2012-09-04 00:00:00', '1899-12-30 07:30:58'), (25410, NULL, 3.9, 26.861, NULL, '53010108', 'GAS', NULL, 105, NULL, 1112, '2012-09-12 00:00:00', '1899-12-30 07:10:00'), (25837, NULL, 4.02, 25.567, NULL, '53010108', 'GAS', NULL, 103.01, NULL, 1112, '2012-09-19 00:00:00', '1899-12-30 07:37:06'), (26200, NULL, 3.93, 22.594, NULL, '53010108', 'GAS', NULL, 89, NULL, 1112, '2012-09-27 00:00:00', '1899-12-30 07:51:00'), (26510, NULL, 3.83, 23.445, NULL, '53010108', 'GAS', NULL, 90.01, NULL, 1112, '2012-10-04 00:00:00', '1899-12-30 07:45:00'), (26853, NULL, 3.71, 24.204, NULL, '53010108', 'GAS', NULL, 90.01, NULL, 1112, '2012-10-12 00:00:00', '1899-12-30 07:39:00'), (27230, NULL, 3.61, 25.973, NULL, '53010108', 'GAS', NULL, 94, NULL, 1112, '2012-10-18 00:00:00', '1899-12-30 07:30:00'), (27640, NULL, 3.47, 29.895, NULL, '53010108', 'GAS', NULL, 104, NULL, 1112, '2012-10-23 00:00:00', '1899-12-30 14:45:19'), (28035, NULL, 3.27, 27.751, NULL, '53010108', 'GAS', NULL, 91, NULL, 1112, '2012-10-29 00:00:00', '1899-12-30 07:00:00'), (28396, NULL, 3.27, 26.226, NULL, '53010108', 'GAS', NULL, 86, NULL, 1112, '2012-11-01 00:00:00', '1899-12-30 02:30:00'), (28795, NULL, 3.37, 28.116, NULL, '53010108', 'GAS', NULL, 95, NULL, 1112, '2012-11-06 00:00:00', '1899-12-30 14:15:00'), (29138, NULL, 3.35, 24.412, NULL, '53010108', 'GAS', NULL, 82, NULL, 1112, '2012-11-09 00:00:00', '1899-12-30 07:40:55'), (29550, NULL, 3.47, 29.318, NULL, '53010108', 'GAS', NULL, 102, NULL, 1112, '2012-11-15 00:00:00', '1899-12-30 14:05:32'), (29950, NULL, 3.53, 28.257, NULL, '53010108', 'GAS', NULL, 100, NULL, 1112, '2012-11-27 00:00:00', '1899-12-30 07:12:09'), (30315, NULL, 3.41, 26.323, NULL, '53010108', 'GAS', NULL, 90, NULL, 1112, '2012-12-05 00:00:00', '1899-12-30 14:52:53'), (30650, NULL, 3.23, 25.316, NULL, '53010108', 'GAS', NULL, 82, NULL, 1112, '2012-12-14 00:00:00', '1899-12-30 08:00:00'), (31008, NULL, 3.25, 18.411, NULL, '53010108', 'GAS', NULL, 60, NULL, 1112, '2012-12-19 00:00:00', '1899-12-30 08:27:46'), (31250, NULL, 3.21, 24.23, NULL, '53010108', 'GAS', NULL, 78, NULL, 1112, '2012-12-31 00:00:00', '1899-12-30 07:00:00'), (31566, NULL, 3.17, 26.816, NULL, '53010108', 'GAS', NULL, 85.25, NULL, 1112, '2013-01-08 00:00:00', '1899-12-30 13:45:57'), (31900, NULL, 3.25, 25.774, NULL, '53010108', 'GAS', NULL, 84, NULL, 1112, '2013-01-15 00:00:00', '1899-12-30 13:50:07'), (32188, NULL, 3.33, 24.258, NULL, '53010108', 'GAS', NULL, 81, NULL, 1112, '2013-01-22 00:00:00', '1899-12-30 13:39:29'), (32496, NULL, 3.43, 24.134, NULL, '53010108', 'GAS', NULL, 83, NULL, 1112, '2013-01-28 00:00:00', '1899-12-30 09:00:00'), (32854, NULL, 3.63, 27.204, NULL, '53010108', 'GAS', NULL, 99, NULL, 1112, '2013-02-01 00:00:00', '1899-12-30 14:32:04'), (33143, NULL, 3.61, 23.211, NULL, '53010108', 'GAS', NULL, 84, NULL, 1112, '2013-02-08 00:00:00', '1899-12-30 06:00:00'), (33490, NULL, 3.87, 25.908, NULL, '53010108', 'GAS', NULL, 100.5, NULL, 1112, '2013-02-15 00:00:00', '1899-12-30 14:24:00'), (33849, NULL, 3.83, 27.09, NULL, '53010108', 'GAS', NULL, 104, NULL, 1112, '2013-02-22 00:00:00', '1899-12-30 12:00:00'), (34162, NULL, 3.81, 23.305, NULL, '53010108', 'GAS', NULL, 89, NULL, 1112, '2013-03-01 00:00:00', '1899-12-30 07:00:00'), (34475, NULL, 3.77, 23.287, NULL, '53010108', 'GAS', NULL, 88, NULL, 1112, '2013-03-07 00:00:00', '1899-12-30 07:40:00'), (34840, NULL, 3.63, 24.731, NULL, '53010108', 'GAS', NULL, 90, NULL, 1112, '2013-03-14 00:00:00', '1899-12-30 08:00:00'), (35160, NULL, 3.75, 27.666, NULL, '53010108', 'GAS', NULL, 104, NULL, 1112, '2013-03-20 00:00:00', '1899-12-30 13:00:00'), (35506, NULL, 3.67, 25.007, NULL, '53010108', 'GAS', NULL, 92, NULL, 1112, '2013-03-27 00:00:00', '1899-12-30 13:59:05'), (35800, NULL, 3.57, 19.978, NULL, '53010108', 'GAS', NULL, 71.5, NULL, 1112, '2013-04-04 00:00:00', '1899-12-30 07:30:00'), (36100, NULL, 3.53, 22.323, NULL, '53010108', 'GAS', NULL, 79, NULL, 1112, '2013-04-09 00:00:00', '1899-12-30 14:00:00'), (36432, NULL, 3.47, 22.998, NULL, '53010108', 'GAS', NULL, 80.01, NULL, 1112, '2013-04-16 00:00:00', '1899-12-30 14:57:42'), (36803, NULL, 3.67, 23.375, NULL, '53010108', 'GAS', NULL, 86, NULL, 1112, '2013-04-22 00:00:00', '1899-12-30 08:00:00'), (37171, NULL, 3.65, 25.144, NULL, '53010108', 'GAS', NULL, 92, NULL, 1112, '2013-04-29 00:00:00', '1899-12-30 07:00:00'), (37568, NULL, 3.77, 24.611, NULL, '53010108', 'GAS', NULL, 93, NULL, 1112, '2013-05-06 00:00:00', '1899-12-30 09:00:00'), (37908, NULL, 3.81, 22.256, NULL, '53010108', 'GAS', NULL, 85, NULL, 1112, '2013-05-13 00:00:00', '1899-12-30 08:00:00'), (38295, NULL, 3.77, 23.022, NULL, '53010108', 'GAS', NULL, 87, NULL, 1112, '2013-05-17 00:00:00', '1899-12-30 06:20:00'), (38660, NULL, 3.87, 24.234, NULL, '53010108', 'GAS', NULL, 94, NULL, 1112, '2013-05-24 00:00:00', '1899-12-30 07:00:00'), (39000, NULL, 4.03, 23.025, NULL, '53010108', 'GAS', NULL, 93, NULL, 1112, '2013-06-11 00:00:00', '1899-12-30 07:15:00'), (39342, NULL, 3.95, 23.49, NULL, '53010108', 'GAS', NULL, 93, NULL, 1112, '2013-06-17 00:00:00', '1899-12-30 13:00:00'), (39695, NULL, 3.73, 21.664, NULL, '53010108', 'GAS', NULL, 81, NULL, 1112, '2013-06-24 00:00:00', '1899-12-30 07:15:00'), (40058, NULL, 3.53, 25.996, NULL, '53010108', 'GAS', NULL, 92, NULL, 1112, '2013-06-28 00:00:00', '1899-12-30 13:49:07'), (40430, NULL, 3.42, 23.33, NULL, '53010108', 'GAS', NULL, 80, NULL, 1112, '2013-07-09 00:00:00', '1899-12-30 14:41:37'), (40795, NULL, 3.72, 24.94, NULL, '53010108', 'GAS', NULL, 93, NULL, 1112, '2013-07-16 00:00:00', '1899-12-30 13:31:54'), (41155, NULL, 3.7, 23.996, NULL, '53010108', 'GAS', NULL, 89, NULL, 1112, '2013-07-23 00:00:00', '1899-12-30 14:14:37'), (41536, NULL, 3.57, 24.866, NULL, '53010108', 'GAS', NULL, 89, NULL, 1112, '2013-07-31 00:00:00', '1899-12-30 13:27:51'), (41889, NULL, 3.47, 23.282, NULL, '53010108', 'GAS', NULL, 81, NULL, 1112, '2013-08-09 00:00:00', '1899-12-30 08:00:00'), (42304, NULL, 3.45, 26.019, NULL, '53010108', 'GAS', NULL, 90, NULL, 1112, '2013-08-16 00:00:00', '1899-12-30 10:30:00'), (42633, NULL, 3.47, 22.564, NULL, '53010108', 'GAS', NULL, 78.5, NULL, 1112, '2013-08-26 00:00:00', '1899-12-30 09:30:00'), (42963, NULL, 3.79, 23.006, NULL, '53010108', 'GAS', NULL, 87.4, NULL, 1112, '2013-08-30 00:00:00', '1899-12-30 08:30:00'), (43325, NULL, 3.57, 24.448, NULL, '53010108', 'GAS', NULL, 87.5, NULL, 1112, '2013-09-10 00:00:00', '1899-12-30 07:20:00'), (43683, NULL, 3.53, 23.595, NULL, '53010108', 'GAS', NULL, 83.5, NULL, 1112, '2013-09-16 00:00:00', '1899-12-30 06:00:00'), (44040, NULL, 3.45, 23.127, NULL, '53010108', 'GAS', NULL, 80, NULL, 1112, '2013-09-23 00:00:00', '1899-12-30 08:45:00') ; select vehicle_id , meter , SUM(meter) over(partition by vehicle_id order by date_trans, time_trans) as sum_meter , lead(meter) over(partition by vehicle_id order by date_trans, time_trans) as lead_meter , date_trans , time_trans from @fuel_transaction order by vehicle_id , date_trans , time_trans
run
|
edit
|
history
|
help
0
Import CSV File Into SQL Server Using Bulk Insert
STACK
Q2_30min
test1
DGDFGDFG
exp 8 XIV
1512081 QUAN LY DE TAI
NOT NULL field from SELECT INTO
SQL Server : Calculate Going Step (Yutthana Thanomklay)
Print 10 records