Skip to content

UofT-DSI | SQL - Assignment 1 - #1

Open
mohammadgoudarzirad wants to merge 4 commits into
mainfrom
assignment-one
Open

mohammadgoudarzirad wants to merge 4 commits into
mainfrom
assignment-one

Conversation

@mohammadgoudarzirad

Copy link
Copy Markdown
Owner

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

SQL Assignment 1

What did you learn from the changes you have made?

I learned a lot about SQL, including SELECT, WHERE, CASE, JOIN, aggregate functions, temporary tables, and date functions. I also learned to pay more attention to small syntax mistakes.

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

there were different ways to write the query

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

I made some small syntax mistakes and fixed them by checking the error messages and testing each query

How were these changes tested?

testing queries in DB Browser

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

n/a

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,
COUNT(
) AS booth_rental_count
FROM vendor_booth_assignments
GROUP BY vendor_id*,

Results:

vendor_id booth_rental_count
1 142
3 142
4 211

✅ Query 9:

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

Results:

customer_id customer_first_name customer_last_name total_spent
4 Leyla Abadi 3561.6286
7 Anwar Ali 2921.1743
12 Jalen Carter 3290.0783

⚪ Query 10:

*CREATE TEMP TABLE temp.new_vendor AS
SELECT *
FROM vendor;

INSERT INTO temp.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
LIMIT 25
,

Results:

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

✅ Query 12:

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

Results:

customer_id total_spent
1 152
2 172.5
3 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. However sql file contain special characters that are no executable in the sql

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