Skip to main content

SQL: branch city with assets over 1000000

Short answer

Use SELECT branch_city, SUM(assets) FROM Branch WHERE assets > 1000000 GROUP BY branch_city. This sums assets per city for branches with assets over one million.

Consider database schema: Account (acc_no, branch_name, balance) Branch (branch_name, branch_city, assets) Customer (customer_name, customer_street, customer_city) Loan (loan_no, branch_name, amount) Depositor (customer_name, acc_no) Borrower (customer_name, loan_no) List branch city and total assets where asset > 1000000.

Branch city and assets are both in the Branch table. Since "total assets" is asked per city, group by city and use SUM; the assets > 1000000 condition is on individual branches, so it goes in WHERE.

SELECT   branch_city, SUM(assets) AS total_assets
FROM     Branch
WHERE    assets > 1000000
GROUP BY branch_city;

Sample (tested): Branches Dharan (2000000) and Dh2 (3000000) are in Dharan city, Itahari (1500000) is in Itahari, and Pokhara (500000) is excluded. Output: (Dharan, 5000000), (Itahari, 1500000).

If the question only wants each branch listed with its own assets (no adding up), use:

SELECT branch_city, assets
FROM   Branch
WHERE  assets > 1000000;

To filter on the city total instead of each branch, the condition would move to HAVING SUM(assets) > 1000000.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Database Management System chapter 3 questions →