I
I
Ignat2020-05-07 22:33:25
SQL
Ignat, 2020-05-07 22:33:25

How to add data in a sample?

There is a table with salaries SALARY(id, date, spec_id, value) and a table with company specialists SPECIALIST (id, name, specialty).

How to display the name of a specialist, specialty and total salary for 2017 BUT only for those whose salary for 2017 is more than 5000 rubles?

SELECT sp.name, sp.speciality, SUM(sa.value) AS val 
  FROM salary sa 
  INNER JOIN specialist sp ON sa.spec_id = sp.id 
  WHERE EXTRACT(YEAR FROM sa.date) = 2017 
  GROUP BY sp.id 
  HAVING SUM(sa.value) > 5000

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-05-07
@Rsa97

GROUP BY, SUM(), HAVING, JOIN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question