Skip to content

Assignment 2#17

Open
khsergvl wants to merge 1 commit intomainfrom
assignment-2
Open

Assignment 2#17
khsergvl wants to merge 1 commit intomainfrom
assignment-2

Conversation

@khsergvl
Copy link
Copy Markdown
Owner

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

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

  • I can confirm that my changes are working as intended

@github-actions
Copy link
Copy Markdown

🧪 SQL Queries Run Results

Click to expand/collapse assignment queries execution results✅ Query 1:

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

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


✅ Query 2:

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

Results:
| 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 3:

SELECT cp.,
DENSE_RANK() OVER (PARTITION BY customer_id ORDER BY market_date) AS visit_number

FROM customer_purchases AS cp
WHERE market_date < '2022-04-29'

ORDER BY customer_id, market_date*,

Results:

product_id vendor_id market_date customer_id quantity cost_to_customer_per_qty transaction_time visit_number
5 8 2022-04-08 1 1 6.5 13:10:00 1
5 8 2022-04-15 1 1 6.5 9:54:00 2
4 7 2022-04-19 1 5 3.5 16:09:00 3

✅ Query 4:

*SELECT customer_id, market_date,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY market_date) AS visit_number

FROM customer_purchases
WHERE market_date < '2022-04-29'

GROUP BY customer_id, market_date
ORDER BY customer_id, market_date*,

Results:

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

✅ Query 5:

*SELECT *,
CASE WHEN INSTR(product_name,'-') > 0
THEN LTRIM(RTRIM(SUBSTR(product_name,INSTR(product_name,'-')+1)))
ELSE NULL END AS description

FROM product*,

Results:

product_id product_name product_size product_category_id product_qty_type description
1 Habanero Peppers - Organic medium 1 lbs Organic
2 Jalapeno Peppers - Organic small 1 lbs Organic
3 Poblano Peppers - Organic large 1 unit Organic

✅ Query 7:

*WITH sales_per_market AS (
SELECT
market_date,
ROUND(SUM(quantity * cost_to_customer_per_qty),2) AS sales

FROM customer_purchases
GROUP BY market_date
)

,market_dates_ranked_by_sales AS (
SELECT
market_date,
sales,
RANK() OVER (ORDER BY sales) AS sales_rank_asc,
RANK() OVER (ORDER BY sales DESC) AS sales_rank_desc

FROM sales_per_market
)

SELECT market_date, sales, sales_rank_desc AS sales_rank
FROM market_dates_ranked_by_sales
WHERE sales_rank_asc = 1

UNION

SELECT market_date, sales, sales_rank_desc AS sales_rank
FROM market_dates_ranked_by_sales
WHERE sales_rank_desc = 1*,

Results:

market_date sales sales_rank
2022-12-20 979 1
2023-04-07 272.5 142

✅ Query 8:

*SELECT vendor_name, product_name, sum(price)
FROM (
SELECT DISTINCT
vendor_name,
product_name,
5 * original_price as price

FROM vendor_inventory vi
JOIN vendor v on v.vendor_id = vi.vendor_id
JOIN product p on p.product_id = vi.product_id
) x
CROSS JOIN
(SELECT DISTINCT
customer_id
FROM customer)
GROUP BY vendor_name, product_name*,

Results:

vendor_name product_name sum(price)
Annie's Pies Apple Pie 2340
Annie's Pies Cherry Pie 2340
Annie's Pies Whole Wheat Bread 845

✅ Query 9:

*CREATE TABLE product_units AS

SELECT p.,
CURRENT_TIMESTAMP AS snapshot_timestamp
FROM product AS p
WHERE product_qty_type = "unit"
,

Results:
No data


✅ Query 10:

INSERT INTO product_units (product_id, product_name,
product_size, product_category_id, product_qty_type, snapshot_timestamp)
SELECT
product_id,
product_name,
product_size,
product_category_id,
product_qty_type,
CURRENT_TIMESTAMP
FROM product AS p
WHERE product_id = 7
,

Results:
No data


✅ Query 11:

*WITH older_record AS
(SELECT product_id
,MIN(snapshot_timestamp) AS snapshot_timestamp
FROM product_units
WHERE product_id = 7)

DELETE FROM product_units
WHERE (product_id =
(SELECT product_id
FROM older_record
)
AND snapshot_timestamp =
(SELECT snapshot_timestamp
FROM older_record
))*,

Results:
No data


@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 6, 2026

🧪 SQL Queries Run Results (up to 3 rows)

Click to expand/collapse assignment queries execution results

✅ Query 1:

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

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


✅ Query 2:

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

Results:
| 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 3:

SELECT cp.,
DENSE_RANK() OVER (PARTITION BY customer_id ORDER BY market_date) AS visit_number

FROM customer_purchases AS cp
WHERE market_date < '2022-04-29'

ORDER BY customer_id, market_date*,

Results:

product_id vendor_id market_date customer_id quantity cost_to_customer_per_qty transaction_time visit_number
5 8 2022-04-08 1 1 6.5 13:10:00 1
5 8 2022-04-15 1 1 6.5 9:54:00 2
4 7 2022-04-19 1 5 3.5 16:09:00 3

✅ Query 4:

*SELECT customer_id, market_date,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY market_date) AS visit_number

FROM customer_purchases
WHERE market_date < '2022-04-29'

GROUP BY customer_id, market_date
ORDER BY customer_id, market_date*,

Results:

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

✅ Query 5:

*SELECT *,
CASE WHEN INSTR(product_name,'-') > 0
THEN LTRIM(RTRIM(SUBSTR(product_name,INSTR(product_name,'-')+1)))
ELSE NULL END AS description

FROM product*,

Results:

product_id product_name product_size product_category_id product_qty_type description
1 Habanero Peppers - Organic medium 1 lbs Organic
2 Jalapeno Peppers - Organic small 1 lbs Organic
3 Poblano Peppers - Organic large 1 unit Organic

✅ Query 7:

*WITH sales_per_market AS (
SELECT
market_date,
ROUND(SUM(quantity * cost_to_customer_per_qty),2) AS sales

FROM customer_purchases
GROUP BY market_date
)

,market_dates_ranked_by_sales AS (
SELECT
market_date,
sales,
RANK() OVER (ORDER BY sales) AS sales_rank_asc,
RANK() OVER (ORDER BY sales DESC) AS sales_rank_desc

FROM sales_per_market
)

SELECT market_date, sales, sales_rank_desc AS sales_rank
FROM market_dates_ranked_by_sales
WHERE sales_rank_asc = 1

UNION

SELECT market_date, sales, sales_rank_desc AS sales_rank
FROM market_dates_ranked_by_sales
WHERE sales_rank_desc = 1*,

Results:

market_date sales sales_rank
2022-12-20 979 1
2023-04-07 272.5 142

✅ Query 8:

*SELECT vendor_name, product_name, sum(price)
FROM (
SELECT DISTINCT
vendor_name,
product_name,
5 * original_price as price

FROM vendor_inventory vi
JOIN vendor v on v.vendor_id = vi.vendor_id
JOIN product p on p.product_id = vi.product_id
) x
CROSS JOIN
(SELECT DISTINCT
customer_id
FROM customer)
GROUP BY vendor_name, product_name*,

Results:

vendor_name product_name sum(price)
Annie's Pies Apple Pie 2340
Annie's Pies Cherry Pie 2340
Annie's Pies Whole Wheat Bread 845

⚪ Query 9:

*CREATE TABLE product_units AS

SELECT p.,
CURRENT_TIMESTAMP AS snapshot_timestamp
FROM product AS p
WHERE product_qty_type = "unit"
,

No rows returned


⚪ Query 10:

INSERT INTO product_units (product_id, product_name,
product_size, product_category_id, product_qty_type, snapshot_timestamp)
SELECT
product_id,
product_name,
product_size,
product_category_id,
product_qty_type,
CURRENT_TIMESTAMP
FROM product AS p
WHERE product_id = 7
,

No rows returned


⚪ Query 11:

*WITH older_record AS
(SELECT product_id
,MIN(snapshot_timestamp) AS snapshot_timestamp
FROM product_units
WHERE product_id = 7)

DELETE FROM product_units
WHERE (product_id =
(SELECT product_id
FROM older_record
)
AND snapshot_timestamp =
(SELECT snapshot_timestamp
FROM older_record
))*,

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