🙏 We need your help! SQLtest.online has no ads and lives only on donations. Even a small amount helps. Donate now →
SQL code copied to buffer
Task 33:

Accessory Categories Including Unsold Ones

SQL Server 2022
The buyer wants to see which accessory categories sell and which don't sell at all. Accessory categories are the rows of ProductCategory with ParentProductCategoryID = 4; the sold units are OrderQty in SalesOrderDetail.
Output the columns category (the category name), products (the number of products in the category) and units_sold (0 when nothing was sold), sorted by units_sold from the largest, then by category.
Expected result Columns: 3 · Rows: 12
category products units_sold

Sample rows open after wrong checks: 0 of 2

Write your query below and click "Check it!". Tables are described in the right pane.

Tutorial

By checking a query, you agree that it is stored without your account details and may be included in anonymized datasets, including for AI training. Learn more

The query result will appear here. Ctrl+Enter - Run query