Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Date query

Ramaswami
Level 4
Level 4

Hi Folks, 

 

I want to grab the data from a table whose date is only 2 days ago and ignore if he has more than 1 row in the table. 

 

For example : the below is the table

unique idrespondent idclassoccupationcreated date
111abcabc11/8/2020
121efgo12/8/2020
132huup11/8/2020
142abcabc11/8/2020
153efgo11/8/2020
163dfdf9/8/2020

 

if i run the above table it should return the below : 

 

132huup11/8/2020
142abcabc

11/8/2020

 

I want to grab the people of only 11th Aug and if a guy have created date as 11th aug and some other date i should ignore him. Ideally a guy should have activities only for 11th Aug ( it may be more than 1 row and created by is 11 Aug that's fine) he should not have any more activity on other dates. 

 

 

i have created a query like this : 

 

Ramaswami_0-1597325561242.png

 

related sql query : 

 

SELECT N0.ID FROM tablename N0 WHERE (DateOnly(N0.CREATED_DATE, 'America/Chicago') = AddDays(DateOnly(GetDate(), 'America/Chicago') , -2)) AND NOT ((DateOnly(N0.CREATED_DATE, 'America/Chicago') > AddDays(DateOnly(GetDate(), 'America/Chicago') , -2)) AND (DateOnly(N0.CREATED_DATE, 'America/Chicago') < AddDays(DateOnly(GetDate(), 'America/Chicago') , -2))) LIMIT 10000

 

it is returning me all the rows "NOT" is not working. 

 

0 Replies
Milan_Vucetic
Community Advisor
Community Advisor

Hi @Ramaswami

If I have correct understanding you need unique record which occured before two days: basicaly you want to fetch records which happended exactly two day ago and there is no duplicates on it in the whole table no matter on the date.

You may use  one Query node and make the following aggregation: SELECT respondent_id, Count(unique id) as CT, Max(trunc(created_date)) as MX from your_table GROUP BY respondent_id  and then use another Query or Split node to query previous one with condition CT = 1 and MX = two days ago

Regards,

Milan

Ramaswami
Level 4
Level 4
can we do a count(uniqueid) inside a query component? can you please show me an example
Milan_Vucetic
Community Advisor
Community Advisor

Hi @Ramaswami,

set up like this:

Milan_Vucetic_0-1599032281205.png

  1. Count(@unique_id)
  2. Max(DateOnly(@created_date))
  3. @respondent_id

Regards,

Milan

Ramaswami
Level 4
Level 4

Hi @milan

 

tried like this and it says id should be in group by : 

09/03/2020 6:00:51 AM query PGS-220000 PostgreSQL error: ERROR: column "n0.id" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: ...ATED_DATE, 'America/Chicago')), N0.RESPONDENT_ID, N0.ID FROM...

 

if i keep id in group by it is giving me all the counts like : So for each respondent it is giving me min date of the unique id which is not what we need : 

here the resp is same but because of group by unique id it is giving me all the records. 

count = 1

resp = 123

min date = 2020-08-30

id = 1290

 

count =1

resp = 123

min date = 2020-08-23

id = 122345

Sukrity_Wadhwa
Employee
Employee

Hi @Ramaswami,

Was the proposed solution helpful for you? Please let us know.

Thanks!