7 kyu

Products per Supplier without GROUP BY

Description:

You are working with a database that contains information about various products supplied by different suppliers. The database has a table named products, which has the following schema:

  • id: (integer) - Primary key
  • supplier_id: (integer) – The unique identifier for each supplier.
  • product_name: (varchar) – The name of the product.
  • quantity: (integer) – The quantity of the product in stock.

Write a SQL query to find the total count of rows for each supplier, representing the total number of products (regardless of product name) for each supplier. Your query must not use the GROUP BY clause. But results should be exactly the same as in the query with Group By:

select supplier_id, count(id) as total_products
from products
group by supplier_id
order by supplier_id desc;

Your query must return exactly two columns:

  • supplier_id: The unique identifier for the supplier.
  • total_products: The total number of products for that supplier.

Result set should be ordered by supplier_id in descending order.

GLHF!

SQL
Databases
Restricted

Stats:

CreatedAug 4, 2023
PublishedAug 4, 2023
Warriors Trained415
Total Skips59
Total Code Submissions619
Total Times Completed209
SQL Completions209
Total Stars7
% of votes with a positive feedback rating92% of 32
Total "Very Satisfied" Votes27
Total "Somewhat Satisfied" Votes5
Total "Not Satisfied" Votes0
Total Rank Assessments8
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • bornForThis Avatar
  • dfhwze Avatar
Ad