SQL Help with Aggregate Function Question

I’m practicing aggregate functions with SQL and the following question has me stumped. There is no hint to help guide me through it. Can anyone help?

The energy table shows the 2014 energy consumption and production of each U.S. state, measured in billions of BTU (British Thermal Units). What is the total amount of energy consumed by the US in 2014?

https://www.codecademy.com/practice/paths/data-science/tracks/sql-intermediate/modules/dspath-sql-aggregates#5

From the given link the exact question doesn’t necessarily appear but are you perhaps looking for the SUM of several rows?

1 Like

Whenever a question asks “total amount” (or total), you’re going to use SUM on the column. In this case, it’s the energy column (or whatever it’s called).

This query sums up all the rows the salary column in that table.
Ex: SELECT SUM(salary) FROM salary_disbursement;

The hint about how to form your query is usually (hopefully!) in the question.
When a question asks ‘what’s the average…’ use AVG
When a question asks ‘what’s the largest amount or smallest amount’ use MAX & MIN respectively.
etc.

I’m afraid it’s not a question I’m familiar with. The suggestions above detail how you might go about achieving this. You could drop a quick SELECT * query with LIMIT if you are unsure of the column names since there’s no obvious schema.

2 Likes