I'm not so great with SQL Queriesqueries and would like to know if someone would know the correct Queryquery to return the information below. I'm having a difficult time trying to figure this out. I'm using Microsoft SQL Server 2012. I would appreciate any help.
EXAMPLE DB DATA
ID | DATE | SHIFT#| LINE# | TOTAL | UPTIME (seconds)
1 | 2019-03-13 10:31:29 | 1 | 1 | 345 | 600
2 | 2019-03-13 10:31:39 | 1 | 2 | 254 | 400
3 | 2019-03-13 10:31:49 | 1 | 3 | 198 | 550
4 | 2019-03-13 10:41:29 | 1 | 1 | 300 | 500
5 | 2019-03-13 10:51:39 | 1 | 2 | 154 | 440
6 | 2019-03-13 10:54:49 | 1 | 3 | 298 | 520
7 | 2019-03-13 15:21:19 | 2 | 1 | 100 | 450
8 | 2019-03-13 15:21:29 | 2 | 2 | 330 | 360
9 | 2019-03-13 15:21:39 | 2 | 3 | 400 | 450
10 | 2019-03-13 15:41:19 | 2 | 1 | 200 | 450
11 | 2019-03-13 15:41:29 | 2 | 2 | 300 | 350
12 | 2019-03-13 15:41:39 | 2 | 3 | 400 | 450
13 | 2019-03-14 10:42:09 | 1 | 1 | 345 | 600
14 | 2019-03-14 10:42:19 | 1 | 2 | 254 | 400
15 | 2019-03-14 10:42:29 | 1 | 3 | 198 | 550
16 | 2019-03-14 10:44:09 | 1 | 1 | 340 | 500
17 | 2019-03-14 10:44:19 | 1 | 2 | 204 | 410
18 | 2019-03-14 10:44:29 | 1 | 3 | 178 | 450
19 | 2019-03-14 15:32:29 | 2 | 1 | 200 | 450
20 | 2019-03-14 15:32:39 | 2 | 2 | 300 | 350
21 | 2019-03-14 15:32:49 | 2 | 3 | 400 | 450
22 | 2019-03-14 15:36:29 | 2 | 1 | 210 | 250
23 | 2019-03-14 15:36:39 | 2 | 2 | 320 | 355
24 | 2019-03-14 15:36:49 | 2 | 3 | 450 | 455
###EXAMPLE DB DATA
ID | DATE | SHIFT#| LINE# | TOTAL | UPTIME (seconds)
1 | 2019-03-13 10:31:29 | 1 | 1 | 345 | 600
2 | 2019-03-13 10:31:39 | 1 | 2 | 254 | 400
3 | 2019-03-13 10:31:49 | 1 | 3 | 198 | 550
4 | 2019-03-13 10:41:29 | 1 | 1 | 300 | 500
5 | 2019-03-13 10:51:39 | 1 | 2 | 154 | 440
6 | 2019-03-13 10:54:49 | 1 | 3 | 298 | 520
7 | 2019-03-13 15:21:19 | 2 | 1 | 100 | 450
8 | 2019-03-13 15:21:29 | 2 | 2 | 330 | 360
9 | 2019-03-13 15:21:39 | 2 | 3 | 400 | 450
10 | 2019-03-13 15:41:19 | 2 | 1 | 200 | 450
11 | 2019-03-13 15:41:29 | 2 | 2 | 300 | 350
12 | 2019-03-13 15:41:39 | 2 | 3 | 400 | 450
13 | 2019-03-14 10:42:09 | 1 | 1 | 345 | 600
14 | 2019-03-14 10:42:19 | 1 | 2 | 254 | 400
15 | 2019-03-14 10:42:29 | 1 | 3 | 198 | 550
16 | 2019-03-14 10:44:09 | 1 | 1 | 340 | 500
17 | 2019-03-14 10:44:19 | 1 | 2 | 204 | 410
18 | 2019-03-14 10:44:29 | 1 | 3 | 178 | 450
19 | 2019-03-14 15:32:29 | 2 | 1 | 200 | 450
20 | 2019-03-14 15:32:39 | 2 | 2 | 300 | 350
21 | 2019-03-14 15:32:49 | 2 | 3 | 400 | 450
22 | 2019-03-14 15:36:29 | 2 | 1 | 210 | 250
23 | 2019-03-14 15:36:39 | 2 | 2 | 320 | 355
24 | 2019-03-14 15:36:49 | 2 | 3 | 450 | 455
I'd like the result of the Queryquery to be 1one line per DATEDATE
, SHIFT#SHIFT#
, & LINE#and LINE#
. The SUMSUM
of TOTALthe TOTAL
field and the SumSUM
of the UPTIMEUPTIME
field needs to be included. I'm trying to get it to look like this example:
RETURNED RECORD FORMAT
DATE | SHIFT# | LINE# | SUM TOTAL | SUM UPTIME
2019-03-13 | 1 | 1 | 645 | 1100
2019-03-13 | 1 | 2 | 399 | 840
2019-03-13 | 1 | 3 | 494 | 1070
2019-03-13 | 2 | 1 | 300 | 900
2019-03-13 | 2 | 2 | 630 | 710
2019-03-13 | 2 | 3 | 800 | 900
2019-03-14 | 1 | 1 | 685 | 1100
2019-03-14 | 1 | 2 | 458 | 810
2019-03-14 | 1 | 3 | 376 | 1000
2019-03-14 | 2 | 1 | 410 | 700
2019-03-14 | 2 | 2 | 620 | 705
2019-03-14 | 2 | 3 | 850 | 905
I'd appreciate any help anyone can provide. Thanks.###RETURNED RECORD FORMAT
DATE | SHIFT# | LINE# | SUM TOTAL | SUM UPTIME
2019-03-13 | 1 | 1 | 645 | 1100
2019-03-13 | 1 | 2 | 399 | 840
2019-03-13 | 1 | 3 | 494 | 1070
2019-03-13 | 2 | 1 | 300 | 900
2019-03-13 | 2 | 2 | 630 | 710
2019-03-13 | 2 | 3 | 800 | 900
2019-03-14 | 1 | 1 | 685 | 1100
2019-03-14 | 1 | 2 | 458 | 810
2019-03-14 | 1 | 3 | 376 | 1000
2019-03-14 | 2 | 1 | 410 | 700
2019-03-14 | 2 | 2 | 620 | 705
2019-03-14 | 2 | 3 | 850 | 905