Skip to content

Assignment 2#4

Open
bkirsh99 wants to merge 4 commits intomainfrom
assignment-2
Open

Assignment 2#4
bkirsh99 wants to merge 4 commits intomainfrom
assignment-2

Conversation

@bkirsh99
Copy link
Copy Markdown
Owner

@bkirsh99 bkirsh99 commented Apr 7, 2026

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

I am trying to run AutoRunner on a copy of my branch for assignment 2.

What did you learn from the changes you have made?

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

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

How were these changes tested?

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

Checklist

  • [x ] I can confirm that my changes are working as intended

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

🧪 SQL Queries Run Results (up to 3 rows)

Click to expand/collapse assignment queries execution results

✅ Query 1:

SELECT
COALESCE(product_name, '') || ', ' ||
COALESCE(product_size, '') || ' (' ||
COALESCE(product_qty_type, 'unit') || ')'
FROM product
,

Results:
| COALESCE(product_name, '') || ', ' ||
COALESCE(product_size, '') || ' (' ||
COALESCE(product_qty_type, 'unit') || ')' |
| --- |
| Habanero Peppers - Organic, medium (lbs) |
| Jalapeno Peppers - Organic, small (lbs) |
| Poblano Peppers - Organic, large (unit) |


✅ Query 2:

SELECT
customer_id,
market_date,
DENSE_RANK() OVER (
PARTITION BY customer_id
ORDER BY market_date
) AS visit_number
FROM (
SELECT DISTINCT customer_id, market_date
FROM customer_purchases
)
WHERE market_date < '2022-04-29'
,

Results:

customer_id market_date visit_number
1 2022-04-08 1
1 2022-04-15 2
1 2022-04-19 3

✅ Query 3:

*SELECT
customer_id,
market_date,
DENSE_RANK() OVER (
PARTITION BY customer_id
ORDER BY market_date DESC
) AS visit_rank
FROM (
SELECT DISTINCT customer_id, market_date
FROM customer_purchases
);

SELECT *
FROM (
SELECT
customer_id,
market_date,
DENSE_RANK() OVER (
PARTITION BY customer_id
ORDER BY market_date DESC
) AS visit_rank
FROM (
SELECT DISTINCT customer_id, market_date
FROM customer_purchases
)
)
WHERE visit_rank = 1*,

Results:

customer_id market_date visit_rank
1 2023-10-13 1
2 2023-10-13 1
3 2023-10-10 1

✅ Query 4:

SELECT
customer_id,
product_id,
market_date,
COUNT(
) OVER (
PARTITION BY customer_id, product_id
) AS purchase_count
FROM customer_purchases
WHERE market_date < '2022-04-29'*,

Results:

customer_id product_id market_date purchase_count
1 4 2022-04-19 2
1 4 2022-04-26 2
1 5 2022-04-08 6

✅ Query 5:

SELECT
product_name,
TRIM(
CASE
WHEN INSTR(product_name, '-') > 0 THEN
SUBSTR(product_name, INSTR(product_name, '-') + 1)
ELSE NULL
END
) AS description
FROM product
,

Results:

product_name description
Habanero Peppers - Organic Organic
Jalapeno Peppers - Organic Organic
Poblano Peppers - Organic Organic

❌ Query 6:

SELECT *
FROM product
WHERE product_size REGEXP '[0-9]'
,

Error:
no such function: REGEXP


✅ Query 7:

*WITH sales_by_date AS (
SELECT
market_date,
SUM(quantity * cost_to_customer_per_qty) AS total_sales
FROM customer_purchases
GROUP BY market_date
),
ranked AS (
SELECT *,
RANK() OVER (ORDER BY total_sales DESC) AS best_rank,
RANK() OVER (ORDER BY total_sales ASC) AS worst_rank
FROM sales_by_date
)

SELECT market_date, total_sales, 'Best Day' AS label
FROM ranked
WHERE best_rank = 1

UNION

SELECT market_date, total_sales, 'Worst Day' AS label
FROM ranked
WHERE worst_rank = 1*,

Results:

market_date total_sales label
2022-12-20 979 Best Day
2023-04-07 272.5 Worst Day

✅ Query 8:

SELECT
v.vendor_name,
p.product_name,
COUNT(c.customer_id) * 5 * vi.original_price AS total_revenue
FROM vendor_inventory vi
JOIN vendor v
ON vi.vendor_id = v.vendor_id
JOIN product p
ON vi.product_id = p.product_id
CROSS JOIN customer c
GROUP BY v.vendor_name, p.product_name, vi.original_price
,

Results:

vendor_name product_name total_revenue
Annie's Pies Apple Pie 332280
Annie's Pies Cherry Pie 332280
Annie's Pies Whole Wheat Bread 119990

⚪ Query 9:

*CREATE TABLE product_units AS
SELECT ,
CURRENT_TIMESTAMP AS snapshot_timestamp
FROM product
WHERE product_qty_type = 'unit'
,

No rows returned


⚪ Query 10:

*INSERT INTO product_units
SELECT ,
CURRENT_TIMESTAMP
FROM product
WHERE product_name = 'Apple Pie'
LIMIT 1
,

No rows returned


⚪ Query 11:

DELETE FROM product_units
WHERE product_name = 'Apple Pie'
AND snapshot_timestamp < (
SELECT MAX(snapshot_timestamp)
FROM product_units
WHERE product_name = 'Apple Pie'
)
,

No rows returned


⚪ Query 12:

*ALTER TABLE product_units
ADD current_quantity INT;

UPDATE product_units
SET current_quantity = COALESCE((
SELECT vi.quantity
FROM vendor_inventory vi
WHERE vi.product_id = product_units.product_id
ORDER BY vi.market_date DESC
LIMIT 1
), 0)*,

No rows returned


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.

1 participant