Skip to content
Advertisement

Find two values of one Column based on value of another column per ID

I have a sqlite db with one table that called Loan. This table with sample data is here: Loan Table at sqlfiddle.com

This table contains below Columns:

Now, I need a query to show desired result, contain

[empid],[Codepayid],[Lval-1],[Lval-2],[Sum(Lint)],[Lrmn-1],[Lrmn-2],

With this Conditions:

For example:

Result:

EmpID CodepayID Lval1 Lval2 Sum(Lint) Lrmn1 Lrmn2
12450400 649 405480 405485 270320 337900 202740

Advertisement

Answer

Use FIRST_VALUE() and SUM() window functions:

See the demo.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement