Well, I got table Workers in my DB. There are 4 columns id,name,salary and department. I need to show list of departments where count of workers with salary more than 90% of max salary value in row and where count of workers with such salary is more than 15% of workers count in department.
At first I made such query which shows all rows with workers who have big salary
SELECT *
FROM `Workers`
WHERE id IN (
SELECT `id`
FROM `Workers`
WHERE `salary` > 0.9 * (SELECT MAX( `salary` )
FROM `Workers`))
Maybe I asking really silly thing but I stuck and i don’t know really how to make next step to throw from it workers who have big salary but in their departments are less than 15% got salaries like this.
This is ugly but it should work: