Using Derived Relations

  • 01/11/2023
  • SQL
No Comments
¨  More typical is a query against aggregate values
  • Example:

“Find the largest total account balance of any branch.”

🞑 Need to compute total account balance for each branch first.

SELECT branch_name, SUM(balance) AS total_bal

FROM account GROUP BY branch_name;

🞑 Then we can easily find the answer:

SELECT MAX(total_bal) AS largest_total

FROM (SELECT branch_name,

SUM(balance) AS total_bal

FROM account GROUP BY branch_name)

AS totals (branch_name, tot_bal);

About us and this blog

We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

Subscribe to our newsletter!

More from our blog

See all posts
No Comments

Recent Posts