I have the below table.
date label time 2014-04-06 A 12:05:56 2014-04-06 A 23:02:32 2014-04-06 B 8:39:25 2014-04-06 B 12:36:37 2014-04-06 C 12:20:43 2014-04-06 C 12:56:44 2014-04-06 D 20:52:22 2014-04-06 E 22:25:30 2014-04-06 F 12:16:15 2014-04-06 F 12:31:09 2014-04-06 F 17:12:06 2014-04-06 G 7:48:32 2014-04-06 H 17:58:11 2014-04-05 I 12:05:56 2014-04-05 I 20:02:32 2014-04-05 I 23:57:32 2014-04-05 J 12:36:37 2014-04-05 K 12:20:43 2014-04-05 L 12:56:44 2014-04-05 M 20:52:22 2014-04-05 M 22:25:30 2014-04-05 N 12:16:15 2014-04-05 O 12:31:09 2014-04-05 O 17:12:06 2014-04-05 P 7:48:32 2014-04-05 Q 17:58:11 2014-04-06 R 1:05:56 2014-04-06 R 5:02:32 2014-04-06 R 8:39:25 2014-04-06 R 12:36:37 2014-04-06 S 12:20:43 2014-04-06 S 12:56:44 2014-04-06 S 20:52:22 2014-04-06 T 22:25:30 2014-04-06 U 12:16:15 2014-04-06 V 12:31:09 2014-04-06 W 3:48:32 2014-04-06 W 7:48:32 2014-04-06 W 17:58:11
I'm trying to create a view with this output.
date label time status 2014-04-06 A 12:05:56 Repeat 2014-04-06 A 23:02:32 Unique 2014-04-06 B 8:39:25 Repeat 2014-04-06 B 12:36:37 Unique 2014-04-06 C 12:20:43 Repeat 2014-04-06 C 12:56:44 Unique 2014-04-06 D 20:52:22 Unique 2014-04-06 E 22:25:30 Unique 2014-04-06 F 12:16:15 Repeat 2014-04-06 F 12:31:09 Repeat 2014-04-06 F 17:12:06 Unique 2014-04-06 G 7:48:32 Unique 2014-04-06 H 17:58:11 Unique 2014-04-05 I 12:05:56 Repeat 2014-04-05 I 20:02:32 Repeat 2014-04-05 I 23:57:32 Unique 2014-04-05 J 12:36:37 Unique 2014-04-05 K 12:20:43 Unique 2014-04-05 L 12:56:44 Unique 2014-04-05 M 20:52:22 Repeat 2014-04-05 M 22:25:30 Unique 2014-04-05 N 12:16:15 Unique 2014-04-05 O 12:31:09 Repeat 2014-04-05 O 17:12:06 Unique 2014-04-05 P 7:48:32 Unique 2014-04-05 Q 17:58:11 Unique 2014-04-06 R 1:05:56 Repeat 2014-04-06 R 5:02:32 Repeat 2014-04-06 R 8:39:25 Repeat 2014-04-06 R 12:36:37 Unique 2014-04-06 S 12:20:43 Repeat 2014-04-06 S 12:56:44 Repeat 2014-04-06 S 20:52:22 Unique 2014-04-06 T 22:25:30 Unique 2014-04-06 U 12:16:15 Unique 2014-04-06 V 12:31:09 Unique 2014-04-06 W 3:48:32 Repeat 2014-04-06 W 7:48:32 Repeat 2014-04-06 W 17:58:11 Unique
The criteria for the status column will be like this.
I wanted to loop in each row based on the label and time column criteria the status column is derived.
Suppose the 1st row of label = 2nd row of label and the difference of time for 2nd row and 1st row is greater 24:00:00 then it must be yes else no.
I do it like this in excel.
=IF(AND(B2=B3,C3-C2>1),"Yes","No")
I'm new to PostgreSQL and database.
Any suggestions or help will be very much helpful in passing through this.
Thanks in advance.
lag.DandE?B?Awhich has been repeated twice with in 24 hours. In this case. The firstAwill be counted as a repeat and the secondAwill be considered as unique one. Any labels with n number of times with in 24 hour span, only the last entry will be unique and the rest will be counted as repeat. And in the answer provided for theFlabel I getno, yes nobut the actual value must beyes, yes, no. Hope you are clear now.