BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
gyambqt
Obsidian | Level 7

Hi Experts,

I have a SQL as shown below:

 

 

select stg.* from(
select stg.ID, stg.revision_dttm, stg.no,date, stg.value,
row_number() over(partition by stg.ID order by stg.value desc,
stg.date desc) as tmp_row
from table1 stg
) stg


inner join table2 tref1
on stg.ID = tref1.ID and
stg.revision_dttm = tref1.revision_dttm
and tref1.id2='1'

 

 

each time when I run script above I was getting different result for tmp_row. why is this happening?

 

 

 

run1:

ID               revision_dttm                    no                       value                  date                             tmp_row
1                2020-02-14 08:12:49         a                         0                     2020-01-20 00:00:00         1
1               2020-02-14 08:12:49          b                         0                       2020-01-20 00:00:00        2

 

run2:

ID               revision_dttm                    no                       value                  date                             tmp_row
1                2020-02-14 08:12:49         a                         0                     2020-01-20 00:00:00         2
1               2020-02-14 08:12:49          b                         0                       2020-01-20 00:00:00        1

 

1 ACCEPTED SOLUTION

Accepted Solutions
JBailey
Barite | Level 11

Hi @gyambqt 

 

Just a guess.

 

The ORDER BY clause sorts on stg.value and stg.date. These values are the same in your output. So, the sort is coming into the PARTITION clause in a different order but is still correct. Greenplum is a highly parallel database. Nodes could be producing intermediate result sets at different times. Thus, producing a random assignment of the tmp_row value. 

 

Best wishes,

@JBailey 

View solution in original post

1 REPLY 1
JBailey
Barite | Level 11

Hi @gyambqt 

 

Just a guess.

 

The ORDER BY clause sorts on stg.value and stg.date. These values are the same in your output. So, the sort is coming into the PARTITION clause in a different order but is still correct. Greenplum is a highly parallel database. Nodes could be producing intermediate result sets at different times. Thus, producing a random assignment of the tmp_row value. 

 

Best wishes,

@JBailey 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 400 views
  • 0 likes
  • 2 in conversation