Sum of a field with respect to another field <p>I have a table of employees Salary named as <strong>empSalary</strong>.</p> <p><img src="https://i.stack.imgur.com/mOFVj.png" alt="empSalary"></p> <p>I want to calculate sum of salaries issued by each department. What comes to my mind is </p> <pre><code>Select sum(Salary) from empSalary where deptId = (Select deptId from empSalary) </code></pre> <p>This statement gives me <strong>5100</strong> which is the sum of Salary where <strong>deptId = 1</strong>. How is this possible using only sql query? Sorry for the question title as i was unable to find words.</p>