I'm trying to get back into SQL query and am having a frustrating problem. I have two questions:
I'm trying to take all items in my dataset and rank them by partitions. I researched this and think it should look like this:
select g.ticker, g.sector, g.industry, g.countryname, g.exchange, c.carbon, c.year,
ROW_NUMBER() OVER (
PARTITION BY g.sector, g.industry, g.countryname, g.exchange
ORDER BY c.carbon DESC
) AS 'Rank'
from "General" g
INNER JOIN carbon c ON upper(c.ticker) =g.ticker ;
The output would be a rank for each group in the partition in this case it would be sector, industry, country name and exchange then the rows are ranked based on their carbon emissions.
I'm getting this error:
Error occurred during SQL script execution
Reason:
SQL Error [42601]: ERROR: syntax error at or near "'Rank'"
Position: 1305
if I remove the rank section, the data joins and provides results(obviously not ranked like I want but I know the base query works). What am I doing wrong?
Second(related) question, I forgot how much I hated SQL error messages. The above error tells me there's syntax error then I went to the docs and couldn't see anything different in my code vs their example. Assuming lack of experience, is there a better way to get actionable error messages(i.e. in python I get a stack trace that I can read to see what part of my code went wrong)?
Thank you!