K
K
Konstantin2018-09-21 20:47:30
SQL
Konstantin, 2018-09-21 20:47:30

How to highlight the last 3 contracts in a SQL query?

There is a Contracts schema :

  • skp_contract INT
  • approval_date DATETIME
  • code_employee INT
  • amt_credit INT

You need to display the last 3 contracts of each employee. I have no idea how to get the last 3 contracts for each employee. It turned out to display the sum of all contracts for each, but not the last. Everything he wrote:
SELECT code_employee, SUM(amt_credit) 
FROM Contracts 
GROUP BY code_employee;

Can you suggest where to dig ?5ba52f993fa74263677473.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nozzy, 2018-09-21
@nicebmw9

Look here:
https://dba.stackexchange.com/questions/116142/get...

D
Dave, 2018-09-21
@djay

SELECT code_employee, SUM(amt_credit) 
FROM Contracts 
GROUP BY code_employeem, approval_date 
ORDER BY approval_date DESC
LIMIT 3

Sort in descending order by acceptance date.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question