Skip to content

Completed queries for assignment one#1

Open
haichenz wants to merge 3 commits intomainfrom
assignment-one
Open

Completed queries for assignment one#1
haichenz wants to merge 3 commits intomainfrom
assignment-one

Conversation

@haichenz
Copy link
Copy Markdown
Owner

@haichenz haichenz commented Nov 16, 2025

What changes are you trying to make? (e.g. Adding or removing code, refactoring existing code, adding reports)

completed assignment one of SQL module.

What did you learn from the changes you have made?

intended course content.

Was there another approach you were thinking about making? If so, what approach(es) were you thinking of?

none.

Were there any challenges? If so, what issue(s) did you face? How did you overcome it?

none.

How were these changes tested?

test with test queries and results are expected.

A reference to a related issue in your repository (if applicable)

not applicable.

Checklist

  • I can confirm that my changes are working as intended

Copy link
Copy Markdown

@monzchan monzchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!


SELECT *, quantity * cost_to_customer_per_qty as price
FROM customer_purchases
WHERE product_id BETWEEN 8 and 10;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be customer_id instead of product_id

-- option 1
SELECT *, quantity * cost_to_customer_per_qty as price
FROM customer_purchases
WHERE product_id >= 8 and product_id <= 10;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be customer_id instead of product_id


SELECT product_id, product_name,
case when product_qty_type = 'unit' THEN 'unit' else 'bulk' end as prod_qty_type_condensed,
CASE WHEN product_name like '%peppers%' THEN 1 else 0 end as pepper_flag
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LIKE '%pepper%' -- this will not match "Pepper" or "PEPPER". Consider using LOWER(...) LIKE '...'

/* 1. Write a query that determines how many times each vendor has rented a booth
at the farmer’s market by counting the vendor booth assignments per vendor_id. */

SELECT vendor_id, count (booth_number)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question requires he vendor booth assignments per vendor_id. count (*) or count (vendor_id) would be more appropriate here.

customer_last_name,
sum(cp.quantity * cp.cost_to_customer_per_qty) as tot_spd
FROM customer c
left join customer_purchases cp
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LEFT JOIN includes customers with no purchases, generating NULL totals. INNER JOIN would be a better option here.

VALUES
(10, 'Thomass Superfood Store', 'Fresh Focused', 'Thomas', 'Rosenthal');

SELECT * FROM "new_vendor";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here should be temp.new_vendor instead of new_vendor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants