Guided Project: Answering Business Questions using SQL ORDER BY keyword not working

%%sql
SELECT 
    invoice.billing_city 'transaction cities', 
    COUNT(invoice.invoice_id) 'transaction count'
FROM
    invoice
JOIN
    invoice_line
    ON invoice.invoice_id=invoice_line.invoice_id
    AND invoice.billing_country='France'
JOIN
    track
    ON invoice_line.track_id=track.track_id
JOIN
    genre
    ON track.genre_id=genre.genre_id
    AND genre.name='Alternative & Punk'
GROUP BY invoice.billing_city
ORDER BY 'transaction count' DESC

The transaction count column is not being ordered correctly in descended order,
please advise on how to fix?

I remember having this problem. You should consider changing 'transaction cities' and 'transaction counts' to transaction_cities and transaction_counts . Put the _ and remove the ' '.

The code below sorted properly.

Cheers!

%%sql
SELECT 
    invoice.billing_city transaction_cities, 
    COUNT(invoice.invoice_id) transaction_count
FROM
    invoice
JOIN
    invoice_line
    ON invoice.invoice_id=invoice_line.invoice_id
    AND invoice.billing_country='France'
JOIN
    track
    ON invoice_line.track_id=track.track_id
JOIN
    genre
    ON track.genre_id=genre.genre_id
    AND genre.name='Alternative & Punk'
GROUP BY invoice.billing_city
ORDER BY transaction_count DESC
1 Like

Thanks again monorienaghogho

1 Like