Stack
|
postgresql_version |
1 |
PostgreSQL 9.6.2, compiled by Visual C++ build 1800, 64-bit |
|
id |
user |
contact |
barcode |
date |
in |
out |
dif |
1 |
1 |
USER3 |
Pepito Marquez |
346234 |
30.05.2017 05:00:00 |
100 |
50 |
50 |
2 |
2 |
USER2 |
Guillermo Tole |
987654 |
02.06.2017 05:03:00 |
200 |
150 |
50 |
3 |
3 |
USER3 |
Pepito Marquez |
346234 |
05.06.2017 05:37:00 |
150 |
120 |
30 |
4 |
4 |
USER2 |
Guillermo Tole |
281460 |
05.06.2017 23:35:00 |
120 |
100 |
20 |
5 |
5 |
USER2 |
Guillermo Tole |
987654 |
07.06.2017 05:35:00 |
300 |
210 |
90 |
6 |
6 |
USER3 |
Pepito Marquez |
346234 |
08.06.2017 05:37:00 |
300 |
280 |
20 |
7 |
7 |
USER2 |
Guillermo Tole |
281460 |
09.06.2017 05:37:00 |
190 |
120 |
70 |
8 |
8 |
USER2 |
Guillermo Tole |
281460 |
12.06.2017 05:26:00 |
230 |
190 |
40 |
9 |
9 |
USER3 |
Juan Rulfo |
123456 |
12.06.2017 05:37:00 |
450 |
300 |
150 |
10 |
10 |
USER2 |
Guillermo Tole |
987654 |
13.06.2017 05:27:00 |
400 |
380 |
20 |
11 |
11 |
USER3 |
Pepito Marquez |
346234 |
14.06.2017 05:37:00 |
450 |
300 |
150 |
12 |
12 |
USER3 |
Juan Rulfo |
123456 |
15.06.2017 05:37:00 |
450 |
300 |
150 |
13 |
13 |
USER2 |
Guillermo Tole |
281460 |
15.06.2017 05:36:00 |
310 |
220 |
90 |
14 |
14 |
USER3 |
Pepito Marquez |
346234 |
15.06.2017 05:37:00 |
600 |
360 |
240 |
15 |
15 |
USER2 |
Guillermo Tole |
987654 |
16.06.2017 05:27:00 |
500 |
420 |
80 |
16 |
16 |
USER2 |
Guillermo Tole |
987654 |
19.06.2017 05:27:00 |
600 |
550 |
50 |
17 |
17 |
USER3 |
Pepito Marquez |
346234 |
19.06.2017 05:37:00 |
750 |
450 |
300 |
18 |
18 |
USER2 |
Guillermo Tole |
281460 |
20.06.2017 09:37:00 |
490 |
410 |
80 |
19 |
19 |
USER3 |
Pepito Marquez |
346234 |
21.06.2017 05:37:00 |
800 |
550 |
250 |
20 |
20 |
USER2 |
Guillermo Tole |
987654 |
23.06.2017 05:27:00 |
700 |
690 |
10 |
21 |
21 |
USER3 |
Pepito Marquez |
346234 |
27.06.2017 05:37:00 |
900 |
690 |
210 |
22 |
22 |
USER2 |
Guillermo Tole |
987654 |
28.06.2017 05:27:00 |
800 |
760 |
40 |
23 |
23 |
USER2 |
Guillermo Tole |
281460 |
29.06.2017 05:37:00 |
600 |
530 |
70 |
24 |
24 |
USER3 |
Pepito Marquez |
346234 |
30.06.2017 05:37:00 |
1050 |
900 |
150 |
25 |
25 |
USER3 |
Pepito Marquez |
346234 |
03.07.2017 05:37:00 |
1200 |
1000 |
200 |
26 |
26 |
USER2 |
Guillermo Tole |
987654 |
04.07.2017 05:27:00 |
900 |
830 |
70 |
|
first |
1 |
this query do apart the results and keep only the week before last, but this shows repetitions of barcode column and it also sum it |
|
user |
contact |
barcode |
date |
in |
out |
dif |
1 |
USER2 |
Guillermo Tole |
987654 |
16.06.2017 05:27:00 |
500 |
420 |
80 |
2 |
USER2 |
Guillermo Tole |
281460 |
15.06.2017 05:36:00 |
310 |
220 |
90 |
3 |
USER2 |
Guillermo Tole |
987654 |
13.06.2017 05:27:00 |
400 |
380 |
20 |
4 |
USER2 |
Guillermo Tole |
281460 |
12.06.2017 05:26:00 |
230 |
190 |
40 |
5 |
USER3 |
Juan Rulfo |
123456 |
15.06.2017 05:37:00 |
450 |
300 |
150 |
6 |
USER3 |
Juan Rulfo |
123456 |
12.06.2017 05:37:00 |
450 |
300 |
150 |
7 |
USER3 |
Pepito Marquez |
346234 |
15.06.2017 05:37:00 |
600 |
360 |
240 |
8 |
USER3 |
Pepito Marquez |
346234 |
14.06.2017 05:37:00 |
450 |
300 |
150 |
|
second |
1 |
this query do apart the results and keep only the week before last, this doesn`t show repetitions, but it does make the sum in background |
|
user |
contact |
barcode |
date |
in |
out |
dif |
sum |
1 |
USER3 |
Juan Rulfo |
123456 |
15.06.2017 05:37:00 |
450 |
300 |
150 |
300 |
2 |
USER2 |
Guillermo Tole |
281460 |
15.06.2017 05:36:00 |
310 |
220 |
90 |
230 |
3 |
USER3 |
Pepito Marquez |
346234 |
15.06.2017 05:37:00 |
600 |
360 |
240 |
390 |
4 |
USER2 |
Guillermo Tole |
987654 |
16.06.2017 05:27:00 |
500 |
420 |
80 |
230 |
|
third |
1 |
even if group by is used, this doesn`t show repetitions, but it does make the sum in background and i only need to be summed the most recent from each barcode for every contact from |
|
user |
contact |
barcode |
date |
in |
out |
dif |
sum |
1 |
USER3 |
Juan Rulfo |
123456 |
15.06.2017 05:37:00 |
450 |
300 |
150 |
300 |
2 |
USER2 |
Guillermo Tole |
281460 |
15.06.2017 05:36:00 |
310 |
220 |
90 |
230 |
3 |
USER3 |
Pepito Marquez |
346234 |
15.06.2017 05:37:00 |
600 |
360 |
240 |
390 |
4 |
USER2 |
Guillermo Tole |
987654 |
16.06.2017 05:27:00 |
500 |
420 |
80 |
230 |
|
|