cancel
Showing results for 
Search instead for 
Did you mean: 

Need a SQL Script for Compare the Row above to that Row

0 Kudos

Hi ,

Looking for some Script here for resolving my issue.

Actual scenario is... A.B,C & Posting date should sort ascending  and to find the Expiration date change.

See the first two ROWs of "C" Column having 1470328PC and Posting Date 12.12.2014 and Expiration Date is 31.05.2016.

and go to the next "C" means 3rd row 1463127PC then the Expiration date of the "C" is 30.04.2016.

here when A,B is constant and C is changing then should compare the Expiration date to the previous Expiration date of "C" column.

Example...  the Expiration Date of 1463127PC is less than 1470328PC's Expiration date.

then need to make that row highlight.

can any one give some pseudo logic for the above scenario.

Thanks in advance,

Thanks,

Gundala

Accepted Solutions (0)

Answers (2)

Answers (2)

henrique_pinto
Active Contributor
0 Kudos

As mentioned, look for the LAG window function:

Window Functions - SAP HANA SQL and System Views Reference - SAP Library

It allows you to access the value of your columns in diff rows.

0 Kudos

Hi Pinto,

Thank you so much for the logic.

Thanks,

Gundala

lbreddemann
Active Contributor
0 Kudos

Gundala,

without the SQL commands to create the table and insert your demo data I am not going to write a SQL that would do what you want.

However, you should check the SQL reference and educate yourself about WINDOW functions.

- Lars

0 Kudos

Lars,

Thanks for your quick reply.

Actually I am working on other reports, meanwhile i just looked out for the SQL script.

Thanks,

Gundala

lbreddemann
Active Contributor
0 Kudos

Well, if you're too busy to provide the data, then better not post your question here.

This is not your "gimme my homework"-one-stop-shop.

0 Kudos

Lars,

If you need the Test data, I am happy to provide that.

I thought you are busy so that i said thanks.

Sorry if I misunderstood you.

Here is the test data.

ABCPosting DatePosting TimeExpiration Date
12599UP021470328PC12.12.201410:45:5231.05.2016
12599UP021470328PC12.12.201415:29:0931.05.2016
12599UP021463127PC15.12.20141:48:0530.04.2016
12599UP021489999PC15.12.201414:02:2931.08.2017
12599UP021489999PC15.12.201414:19:5731.08.2017
12599UP021484206PCC17.12.201415:52:5531.08.2017
12599UP021463127PC22.12.201415:38:0130.04.2016
12599UP021463127PC23.12.20147:39:0030.04.2016
12599UP021463127PC23.12.20148:05:1130.04.2016
12599UP021484206PCC23.12.201412:21:5331.08.2017
12599UP021463127PC27.12.201411:38:3130.04.2016
12599UP011489999PCA17.12.201412:21:0131.08.2017
12599UP011447141PCG20.01.201517:46:3431.01.2016
12599UP011489999PCA28.01.201516:19:5431.08.2017
15001UP02D140007409.12.201416:17:1331.01.2017
15001UP02D140007409.12.201416:24:5731.01.2017
15001UP02H140012712.12.201415:33:3530.04.2017
15001UP02H140012315.01.201512:45:3831.03.2017
15001UP02H140012715.01.201512:45:3830.04.2017
15001UP02H140012323.12.201411:12:3231.03.2017
15001UP02H140012723.12.201411:12:3230.04.2017
15001UP02D140007423.12.201412:21:5331.01.2017
15001UP02F140020623.12.201412:21:5328.02.2017
15001UP01C140019009.12.201416:42:4130.11.2016
15001UP01C140019027.01.20155:26:3330.11.2016
15003UP02D140018515.01.201512:45:3831.01.2017
15003UP02D140018523.12.201411:12:3231.01.2017
15003UP02H140012423.12.201411:12:3230.04.2017
15101UP02D140018723.12.201411:12:3231.01.2017
15101UP02J140006723.12.201411:12:3231.05.2017
15101UP01F140000227.01.20155:26:3331.03.2017

Thanks,

Gundala

lbreddemann
Active Contributor
0 Kudos

So what is anybody supposed to do with this?

How do you think this works?


You just drop your requirement and some arbitrary HTML table and we do the work for you?

As this is a database question, use database tools and commands.

That would be:

CREATE TABLE...

INSERT INTO...

SELECT ...

If you're unable or unwilling to do the very least so that others can reasonably work with your problem, then you'd better just keep it to yourself.

As I already pointed you to the relevant section of the documentation you're now good to proceed.

0 Kudos

Hello,

I just have asked for Pseudo logic.

I did not expect you to do my work.

Understand.

Please do not respond here when you are not  comfort with the issue.

Gundala

lbreddemann
Active Contributor
0 Kudos

What kind of pseudo logic are you expecting here?

What you want to do is doable by a single SELECT statement.

The "pseudo logic" would be

  SELECT { put correct select expression here}

Read the documentation I pointed you to.

Again,"WINDOW functions" are what you want to use here.

And mate, you asked for the help without reading up on documentation or looking for similar requests first here on SCN.

Maybe you'll check the house rules again...

0 Kudos

Dear Lars,

Thank you so much for the Logic.