Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
.vscode/
.sqbpro
#.sqbpro

File renamed without changes.
File renamed without changes.
File renamed without changes
92 changes: 92 additions & 0 deletions 03_homework/homework_-1-6/Homework_4.sqbpro
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?><sqlb_project><db path="/Users/apple/DSI/sql/05_sql/farmersmarket.db" readonly="0" foreign_keys="1" case_sensitive_like="0" temp_store="0" wal_autocheckpoint="1000" synchronous="2"/><attached/><window><main_tabs open="structure browser pragmas query" current="3"/></window><tab_structure><column_width id="0" width="300"/><column_width id="1" width="0"/><column_width id="2" width="100"/><column_width id="3" width="3698"/><column_width id="4" width="0"/><expanded_item id="0" parent="1"/><expanded_item id="1" parent="1"/><expanded_item id="2" parent="1"/><expanded_item id="3" parent="1"/></tab_structure><tab_browse><current_table name="4,5:mainbooth"/><default_encoding codec=""/><browse_table_settings><table schema="main" name="booth" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk="_rowid_"><sort/><column_widths><column index="1" value="84"/><column index="2" value="101"/><column index="3" value="300"/><column index="4" value="68"/></column_widths><filter_values/><conditional_formats/><row_id_formats/><display_formats/><hidden_columns/><plot_y_axes/><global_filter/></table></browse_table_settings></tab_browse><tab_sql><sql name="SQL 1">--COALESCE
SELECT
product_name || ', ' || COALESCE(product_size, '') || ' (' || COALESCE(product_qty_type, 'unit') || ')' AS product_description
FROM product;

--#1 Windowed Functions
SELECT customer_id, market_date
FROM customer_purchases;

SELECT
customer_id,
market_date,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY market_date) AS visit_number
FROM
customer_purchases;

-- #2 Reverse the Numbering

SELECT
customer_id,
market_date
FROM
(
SELECT
customer_id,
market_date,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY market_date DESC) AS visit_number
FROM
customer_purchases
) AS visits
WHERE
visit_number = 1;

-- #3 Using a COUNT()
SELECT
customer_id,
product_id,
market_date,
COUNT(*) OVER (PARTITION BY customer_id, product_id) AS purchase_count
FROM
customer_purchases;


--String Manipulation
SELECT
product_name,
TRIM(SUBSTR(product_name, INSTR(product_name, '-') + 1)) AS description
FROM
product
WHERE
INSTR(product_name, '-') &gt; 0;

--UNION
WITH SalesByDate AS (
SELECT
market_date,
SUM(quantity * cost_to_customer_per_qty) AS total_sales
FROM
customer_purchases
GROUP BY
market_date
),
RankedSales AS (
SELECT
market_date,
total_sales,
RANK() OVER (ORDER BY total_sales DESC) AS sales_rank_desc,
RANK() OVER (ORDER BY total_sales ASC) AS sales_rank_asc
FROM
SalesByDate
)
SELECT
market_date,
total_sales,
'Highest Sales' AS description
FROM
RankedSales
WHERE
sales_rank_desc = 1

UNION

SELECT
market_date,
total_sales,
'Lowest Sales' AS description
FROM
RankedSales
WHERE
sales_rank_asc = 1;

</sql><current_tab id="0"/></tab_sql></sqlb_project>
Binary file added 03_homework/homework_-1-6/Homework_6.pdf
Binary file not shown.
Binary file added 03_homework/homework_-1-6/homework 1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 03_homework/homework_1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 0 additions & 78 deletions 03_homework/homework_1.md

This file was deleted.

23 changes: 0 additions & 23 deletions 03_homework/homework_2.md

This file was deleted.

48 changes: 48 additions & 0 deletions 03_homework/homework_2.sqbpro
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?><sqlb_project><db path="/Users/apple/DSI/sql/05_sql/farmersmarket.db" readonly="0" foreign_keys="1" case_sensitive_like="0" temp_store="0" wal_autocheckpoint="1000" synchronous="2"/><attached/><window><main_tabs open="structure browser pragmas query" current="3"/></window><tab_structure><column_width id="0" width="300"/><column_width id="1" width="0"/><column_width id="2" width="100"/><column_width id="3" width="3698"/><column_width id="4" width="0"/><expanded_item id="0" parent="1"/><expanded_item id="1" parent="1"/><expanded_item id="2" parent="1"/><expanded_item id="3" parent="1"/></tab_structure><tab_browse><current_table name="4,5:mainbooth"/><default_encoding codec=""/><browse_table_settings/></tab_browse><tab_sql><sql name="SQL 1">--SELECT Function by last, first name 10 rows

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

--WHERE #1 Function product IDs 4 and 9.
SELECT * FROM customer_purchases
WHERE product_id IN (4, 9);

--WHERE #2 AND and BETWEEN Function
SELECT *, (quantity * cost_to_customer_per_qty) AS price
FROM customer_purchases
WHERE vendor_id BETWEEN 8 and 10;

-- CASE #1
SELECT product_id,
product_name,
CASE
WHEN product_qty_type = 'unit' THEN 'unit'
ELSE 'bulk'
END AS product_qty_type_condensed
FROM product;


-- CASE #2 - 'pepper' function
SELECT product_id,
product_name,
CASE
WHEN product_qty_type = 'unit' THEN 'unit'
ELSE 'bulk'
END AS prod_qty_type_condensed,
CASE
WHEN LOWER(product_name) LIKE '%pepper%' THEN 1
ELSE 0
END AS pepper_flag
FROM product;

--JOIN
SELECT vendor.vendor_id,
vendor.vendor_name,
vendor_booth_assignments.market_date,
vendor_booth_assignments.booth_number
FROM vendor
INNER JOIN vendor_booth_assignments
ON vendor.vendor_id = vendor_booth_assignments.vendor_id
ORDER BY vendor.vendor_name, vendor_booth_assignments.market_date;
</sql><current_tab id="0"/></tab_sql></sqlb_project>
24 changes: 0 additions & 24 deletions 03_homework/homework_3.md

This file was deleted.

43 changes: 43 additions & 0 deletions 03_homework/homework_3.sqbpro
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?><sqlb_project><db path="/Users/apple/DSI/sql/05_sql/farmersmarket.db" readonly="0" foreign_keys="1" case_sensitive_like="0" temp_store="0" wal_autocheckpoint="1000" synchronous="2"/><attached/><window><main_tabs open="structure browser pragmas query" current="3"/></window><tab_structure><column_width id="0" width="300"/><column_width id="1" width="0"/><column_width id="2" width="100"/><column_width id="3" width="3698"/><column_width id="4" width="0"/><expanded_item id="0" parent="1"/><expanded_item id="1" parent="1"/><expanded_item id="2" parent="1"/><expanded_item id="3" parent="1"/></tab_structure><tab_browse><current_table name="4,5:mainbooth"/><default_encoding codec=""/><browse_table_settings><table schema="main" name="booth" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk="_rowid_"><sort/><column_widths><column index="1" value="84"/><column index="2" value="101"/><column index="3" value="300"/><column index="4" value="68"/></column_widths><filter_values/><conditional_formats/><row_id_formats/><display_formats/><hidden_columns/><plot_y_axes/><global_filter/></table></browse_table_settings></tab_browse><tab_sql><sql name="SQL 1">-- Homework 3 Essential SQL
--AGGREGATE #1
--Vendor booth Acount
SELECT vendor_id, COUNT(*) AS booth_count
FROM vendor_booth_assignments
GROUP BY vendor_id;

--AGGREGATE #2
SELECT c.customer_id, c.customer_last_name, c.customer_first_name,
SUM(cp.quantity * cp.cost_to_customer_per_qty) AS total_spent
FROM customer_purchases cp
JOIN customer c ON cp.customer_id = c.customer_id
GROUP BY c.customer_id, c.customer_last_name, c.customer_first_name
HAVING total_spent &gt;2000
ORDER BY c.customer_last_name, customer_first_name;

-- Temp TABLE
DROP TABLE IF EXISTS new_vendor;
CREATE 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');
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');

--DATE
SELECT
customer_id,
strftime('%m', market_date) AS month,
strftime('%Y', market_date) AS year
FROM customer_purchases;

--customer spent in April 2019
SELECT
customer_id,
SUM(quantity * cost_to_customer_per_qty) AS total_spent
FROM customer_purchases
WHERE
strftime('%m', market_date) = '04' -- Month is April
AND strftime('%Y', market_date) = '2019' -- Year is 2019
GROUP BY customer_id;

</sql><current_tab id="0"/></tab_sql></sqlb_project>
45 changes: 0 additions & 45 deletions 03_homework/homework_4.md

This file was deleted.

Loading