Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

Select the latest id from last week from each different contact withou...

Language: Layout:
absolute service time: 0,51 sec 
edit mode |  history  | discussion
   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 Jesus Zambrano 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 Jesus Zambrano 281460 09.06.2017 05:37:00 190 120 70
8 8 USER2 Jesus Zambrano 281460 13.06.2017 05:26:00 230 190 40
9 9 USER2 Guillermo Tole 987654 13.06.2017 05:27:00 400 380 20
10 10 USER3 Pepito Marquez 346234 13.06.2017 05:37:00 450 300 150
11 11 USER2 Jesus Zambrano 281460 15.06.2017 05:36:00 310 220 90
12 12 USER3 Pepito Marquez 346234 15.06.2017 05:37:00 600 360 240
13 13 USER2 Guillermo Tole 987654 16.06.2017 05:27:00 500 420 80
14 14 USER2 Guillermo Tole 987654 19.06.2017 05:27:00 600 550 50
15 15 USER3 Pepito Marquez 346234 19.06.2017 05:37:00 750 450 300
16 16 USER2 Jesus Zambrano 281460 20.06.2017 09:37:00 490 410 80
17 17 USER3 Pepito Marquez 346234 21.06.2017 05:37:00 800 550 250
18 18 USER2 Guillermo Tole 987654 23.06.2017 05:27:00 700 690 10
19 19 USER3 Pepito Marquez 346234 27.06.2017 05:37:00 900 690 210
20 20 USER2 Guillermo Tole 987654 28.06.2017 05:27:00 800 760 40
21 21 USER2 Jesus Zambrano 281460 29.06.2017 05:37:00 600 530 70
22 22 USER3 Pepito Marquez 346234 30.06.2017 05:37:00 1050 900 150
23 23 USER3 Pepito Marquez 346234 03.07.2017 05:37:00 1200 1000 200
24 24 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 sum
1 USER2 Guillermo Tole 987654 13.06.2017 05:27:00 400 380 110
2 USER2 Guillermo Tole 987654 07.06.2017 05:35:00 300 210 110
3 USER2 Jesus Zambrano 281460 13.06.2017 05:26:00 230 190 110
4 USER2 Jesus Zambrano 281460 09.06.2017 05:37:00 190 120 110
5 USER3 Pepito Marquez 346234 13.06.2017 05:37:00 450 300 170
6 USER3 Pepito Marquez 346234 08.06.2017 05:37:00 300 280 170
   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 sum
1 USER2 Jesus Zambrano 281460 13.06.2017 05:26:00 230 190 110
2 USER3 Pepito Marquez 346234 13.06.2017 05:37:00 450 300 170
3 USER2 Guillermo Tole 987654 13.06.2017 05:27:00 400 380 110
   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 sum
1 USER2 Jesus Zambrano 281460 13.06.2017 05:26:00 230 190 110
2 USER3 Pepito Marquez 346234 13.06.2017 05:37:00 450 300 170
3 USER2 Guillermo Tole 987654 13.06.2017 05:27:00 400 380 110