Skip to content

assignment-1 with .md, logical model and .sq - #1

Open
Xinyu-Liao wants to merge 2 commits into
mainfrom
assignment-1
Open

Xinyu-Liao wants to merge 2 commits into
mainfrom
assignment-1

Conversation

@Xinyu-Liao

Copy link
Copy Markdown
Owner

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

Adding code

What did you learn from the changes you have made?

I've learnt how to add new values by SQL

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

NA

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

I sometimes need to Google for certain queries.

How were these changes tested?

Testing based on existing database

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

NA

Checklist

  • I can confirm that my changes are working as intended

@github-actions

Copy link
Copy Markdown

🧪 SQL Queries Run Results (up to 3 rows)

Click to expand/collapse assignment queries execution results

✅ Query 1:

*SELECT * FROM customer *,

Results:

customer_id customer_first_name customer_last_name customer_postal_code
1 Alejandro Costa M8Y
2 Mei Chen M1L
3 Amir Khan M4H

✅ Query 2:

SELECT *
FROM customer
ORDER BY customer_last_name, customer_first_name
LIMIT 10
,

Results:

customer_id customer_first_name customer_last_name customer_postal_code
4 Leyla Abadi M1L
7 Anwar Ali M6C
12 Jalen Carter M1L

✅ Query 3:

SELECT *
FROM customer_purchases
WHERE product_id = 4 OR product_id = 9
LIMIT 25
,

Results:

product_id vendor_id market_date customer_id quantity cost_per_quantity transaction_time
4 7 2022-04-05 3 1 4 18:44:00
4 7 2022-04-05 4 1 4 18:09:00
4 7 2022-04-05 5 3 4 18:54:00

✅ Query 4:

*SELECT , quantity * cost_per_quantity AS price
FROM customer_purchases
WHERE customer_id BETWEEN 8 AND 10
LIMIT 25
,

Results:

product_id vendor_id market_date customer_id quantity cost_per_quantity transaction_time price
1 7 2022-07-12 8 2.71 6.99 18:35:00 18.9429
1 7 2022-07-15 10 2.34 6.99 10:21:00 16.3566
1 7 2022-07-15 10 2.28 6.99 10:29:00 15.937199999999999

✅ Query 5:

SELECT product_id, product_name,
CASE
WHEN product_qty_type = 'unit' THEN 'unit'
ELSE 'bulk'
END AS prod_qty_type_condensed
FROM product
,

Results:

product_id product_name prod_qty_type_condensed
1 Habanero Peppers - Organic bulk
2 Jalapeno Peppers - Organic bulk
3 Poblano Peppers - Organic unit

✅ Query 6:

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 '%pepper%' THEN 1
ELSE 0
END AS pepper_flag
FROM product
,

Results:

product_id product_name prod_qty_type_condensed pepper_flag
1 Habanero Peppers - Organic bulk 1
2 Jalapeno Peppers - Organic bulk 1
3 Poblano Peppers - Organic unit 1

✅ Query 7:

SELECT *
FROM vendor AS v
INNER JOIN vendor_booth_assignments AS vba
ON v.vendor_id = vba.vendor_id
ORDER BY market_date, vendor_name
LIMIT 24
,

Results:

vendor_id vendor_name vendor_type vendor_owner_first_name vendor_owner_last_name booth_number market_date
8 Annie's Pies Prepared Foods Annie Aquinas 6 2022-04-05
1 Chris's Sustainable Eggs & Meats Eggs & Meats Chris Sylvan 2 2022-04-05
4 Fields of Corn Fresh Focused Samuel Smith 7 2022-04-05

✅ Query 8:

SELECT vendor_id,
SUM (booth_number) AS vendor_renting_times
FROM vendor_booth_assignments
GROUP BY vendor_id
,

Results:

vendor_id vendor_renting_times
1 289
3 142
4 1752

✅ Query 9:

SELECT cp.customer_id, cp.quantity, cp.cost_per_quantity, c.customer_id, c.customer_first_name, c.customer_last_name,
SUM(cp.quantity * cp.cost_per_quantity) AS total_purchase
FROM customer_purchases AS cp
INNER JOIN customer AS c
ON cp.customer_id = c.customer_id
GROUP BY c.customer_id
HAVING total_purchase > 2000
,

Results:

customer_id quantity cost_per_quantity customer_first_name customer_last_name total_purchase
1 2.09 6.99 Alejandro Costa 3530.9187
2 4.24 6.99 Mei Chen 4179.4529
3 2.48 6.99 Amir Khan 3832.1575

⚪ Query 10:

*CREATE TEMP TABLE new_vendor AS
SELECT *
FROM vendor;

INSERT INTO new_vendor (vendor_id, vendor_name, vendor_type, vendor_owner_first_name, vendor_owner_last_name)
VALUES (10, 'Thomass Superfood Store', 'Fresh Focused', 'Thomas', 'Rosenthal' )*,

No rows returned


✅ Query 11:

SELECT customer_id,
STRFTIME('%m', market_date) AS month,
STRFTIME('%Y', market_date) AS year
FROM customer_purchases
,

Results:

customer_id month year
14 07 2022
14 07 2022
15 07 2022

✅ Query 12:

SELECT customer_id,
quantity,
cost_per_quantity,
STRFTIME('%m', market_date) AS month,
STRFTIME('%Y', market_date) AS year,
SUM(quantity * cost_per_quantity) AS total_purchase
FROM customer_purchases
WHERE month = '04' AND year = '2022'
GROUP BY customer_id, year, month
,

Results:

customer_id quantity cost_per_quantity month year total_purchase
1 5 3.5 04 2022 152
2 5 4 04 2022 172.5
3 1 4 04 2022 152

@khsergvl khsergvl left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good! Approved.

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