For this challenge you need to create a SELECT statement that will contain data about departments that had a sale with a price over 98.00 dollars. This SELECT statement will have to use an EXISTS to achieve the task.
departments table schema
- id
- name
sales table schema
- id
- department_id (department foreign key)
- name
- price
- card_name
- card_number
- transaction_date
resultant table schema
- id
- name
Solution:
SELECT
departments.id,
departments.name
FROM
departments
WHERE
EXISTS(
SELECT
*
FROM
sales
WHERE
sales.department_id = departments.id
and sales.price >= 98.00
)
Result:
| id | name |
| 1 | Shoes |
| 2 | Clothing |
| 3 | Jewelry |
| 4 | Tools |
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
| SQL Basics: Simple NULL handling (0) | 2022.07.11 |
|---|---|
| SQL Basics: Simple JOIN and RANK (0) | 2022.07.10 |
| GROCERY STORE: Real Price! (0) | 2022.07.08 |
| GROCERY STORE: Support Local Products (0) | 2022.07.07 |
| SQL with Sailor Moon: Thinking about JOINs... (0) | 2022.07.06 |