URI Online Judge Solution 2606 Categories Using PostgreSQL Query Language.When the data were migrated to the database, there was a small misunderstanding on the DBA.
Your boss needs you to select the ID and the name of the products, whose categorie name start with 'super'.
Schema
productsColumn | Type |
id (PK) | numeric |
name | varchar |
amount | numeric |
price | numeric |
id_categories (FK) | numeric |
categoriesColumn | Type |
id (PK) | numeric |
name | varchar |
Tables
productsid | name | amount | price | id_categories |
1 | Lampshade | 100 | 800 | 4 |
2 | Table for painting | 1000 | 560 | 9 |
3 | Notebook desk | 10000 | 25.50 | 9 |
4 | Computer desk | 350 | 320.50 | 6 |
5 | Chair | 3000 | 210.64 | 9 |
6 | Home alarm | 750 | 460 | 4 |
categoriesid | name |
1 | old stock |
2 | new stock |
3 | modern |
4 | commercial |
5 | recyclable |
6 | executive |
7 | superior |
8 | wood |
9 | super luxury |
10 | vintage |
Output Sample
id | name |
2 | Table for painting |
3 | Notebook desk |
5 | Chair |
URI 2606 Solution in SQL:
SELECT id,name
FROM products
WHERE id_categories
IN (SELECT id FROM Categories WHERE name LIKE 'super%')
Comments
Post a Comment