Group data by multiple columns to get more granular insights. Calculate the number of invoices and total revenue by country AND year.
Write a query grouping invoices by both country and year.
| Column | Type |
|---|---|
| InvoiceId | INTEGER (Primary Key) |
| CustomerId | INTEGER (Foreign Key → Customer.CustomerId) |
| InvoiceDate | TIMESTAMP |
| BillingAddress | TEXT |
| BillingCity | TEXT |
| BillingState | TEXT |
| BillingCountry | TEXT |
| BillingPostalCode | TEXT |
| Total | NUMERIC(10,2) |
EXTRACT(YEAR FROM InvoiceDate)EXTRACT(YEAR FROM date_column) returns the 4-digit year as a numeric. Cast with ::int if you want an integer.
Ready to take your skills to the next level? Enroll in our comprehensive Data Analyst Career Track to master SQL, Python, Excel, and Power BI.
Run your code to see the result here.