Help! Anyone could help me with this Query?

The energy table shows the 2014 energy consumption and production of each U.S. state, measured in billions of BTU (British Thermal Unit). How many states produce more energy than they consume?
THANKS!!!

1 Like

Hi, welcome to the Forums.

Is there a link to a lesson?

What is your code so far? What exactly has you stuck? What have you tried?
Please post your formatted code.

1 Like

Hi @lisalisaj

I’ve just bumped against this question in the Practice section too. I used SELECT to view the table. It has 3 columns:
states TEXT
consumption INTEGER
production INTEGER

I’ve just started SQL and I’m a bit lost. Tried to at least get a list with all states where production is greater than consumption, but to no success. I wrote:

SELECT * FROM energy
WHERE production > consumption;

Link to the practice question here:
https://www.codecademy.com/practice/tracks/analyze-data-sql-query-data/modules/analyze-data-sql-learn-queries

Thanks!

I don’t see a practice question in that link…

Also, you cannot compare columns like that. Are the columns summed? averaged?

1 Like

Hi lisalisaj,

Thanks for replying,

That is all that question has … Indeed, columns cannot be compared like that. It does seem off, but I guess I can go on and continue the course without it.
Let’s leave it…

Thanks again for picking this up once more,

All the best!
Vlad

A bit late but for anyone who has this question:

Use:
SELECT *
FROM energy

This helps you view the table and the names of the columns.

Then you need to use the COUNT function to identify the number of states. Use a WHERE clause to compare production > consumption. So the correct answer should look like:

SELECT COUNT(state)
FROM energy
WHERE production > consumption