From 65edef5738b9c3f50c7462e4633d12a6e0473905 Mon Sep 17 00:00:00 2001 From: Arzoo Bapna <65864642+ar-zoop@users.noreply.github.com> Date: Wed, 18 May 2022 19:11:38 +0530 Subject: [PATCH 01/24] Add files via upload --- select.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 select.txt diff --git a/select.txt b/select.txt new file mode 100644 index 0000000..66a59d7 --- /dev/null +++ b/select.txt @@ -0,0 +1,4 @@ +select * FROM PRODUCT; +select *,PRICE*1.07 FROM PRODUCT; +select *,PRICE*1.07 AS TAXED_PRICE FROM PRODUCT; +select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT; \ No newline at end of file From 04fd30bbb6ab8b7f0f9c0caddad7d6924dacda82 Mon Sep 17 00:00:00 2001 From: Arzoo Bapna <65864642+ar-zoop@users.noreply.github.com> Date: Wed, 18 May 2022 19:12:12 +0530 Subject: [PATCH 02/24] Update README.md --- README.md | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/README.md b/README.md index 0df77fb..64831ff 100644 --- a/README.md +++ b/README.md @@ -1,15 +1 @@ -# Getting Started with SQL - -Thank you for reading *Getting Started with SQL*. These are the database files for the book. - -# Having Download Trouble? - -This book requires basic proficiency in downloading, unzipping, and navigating files and folders. - -If you need assistance in extracting a zipped folder, [please see this short tutorial](http://www.wikihow.com/Open-a-Zip-File). - -For SQLiteStudio, easy-to-use installers are now available so you should not have to unzip/copy/paste SQLiteStudio: https://sqlitestudio.pl/index.rvt?act=download - - -![](https://images-na.ssl-images-amazon.com/images/I/51A7fbsp0EL.jpg) - +This is only for my practice of the book's examples From 08727c35b6ad3f11a1468afc1a345ef3b66a4320 Mon Sep 17 00:00:00 2001 From: Arzoo Bapna <65864642+ar-zoop@users.noreply.github.com> Date: Thu, 19 May 2022 23:48:58 +0530 Subject: [PATCH 03/24] Update select.txt --- select.txt | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/select.txt b/select.txt index 66a59d7..1bcd7d7 100644 --- a/select.txt +++ b/select.txt @@ -1,4 +1,24 @@ select * FROM PRODUCT; select *,PRICE*1.07 FROM PRODUCT; select *,PRICE*1.07 AS TAXED_PRICE FROM PRODUCT; -select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT; \ No newline at end of file +select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT +pragma table_info('customer'); +select name, city||' '||state as location from customer; +select name, region|| ' ' || street_address || ',' || city || ',' || state || ',' || zip as shipping_address from customer; +select * from station_data where year>2005 and year<2010 ; +select * from station_data where year between 2005 and 2010; +select * from station_data where month=3 or month=6 or month=9 or month=12; +select * from station_data where month in (3,6,9,12); +select * from station_data where month not in (3,6,9,12); +select * from station_data where month%3=0; +select * from station_data where length(report_code)=6; +select * from station_data where report_code like 'b%'; +select * from station_data where report_code like 'b_c%'; +select * from station_data where tornado=1 and hail=1; +select * from station_data where tornado and hail; +select * from station_data where tornado=0 and hail; +select * from station_data where not tornado and hail; +select * from station_data where snow_depth is NULL; +select report_code, coalesce(precipitation,0) as rainfall from station_data where precipitation <=0.5; +select * from station_data where (rain=1 and temperature<=32) or snow_depth>0; + From 069dc9c64c348498e2e5646a042c027c38c8e7e0 Mon Sep 17 00:00:00 2001 From: Arzoo Bapna <65864642+ar-zoop@users.noreply.github.com> Date: Fri, 20 May 2022 14:53:10 +0530 Subject: [PATCH 04/24] Update select.txt --- select.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/select.txt b/select.txt index 1bcd7d7..299f701 100644 --- a/select.txt +++ b/select.txt @@ -21,4 +21,10 @@ select * from station_data where not tornado and hail; select * from station_data where snow_depth is NULL; select report_code, coalesce(precipitation,0) as rainfall from station_data where precipitation <=0.5; select * from station_data where (rain=1 and temperature<=32) or snow_depth>0; - +select count(*) from station_data where tornado; +select year, month, count(*) as count from station_data group by 1; +select * from station_data where tornado=1 group by 1,2 order by 1,4 desc; +select year, sum(snow_depth) from station_data where year>=2000 group by year; +select year, sum(snow_depth) as total_snow , sum(precipitation) as total_precipitation, max(precipitation) from station_data where year>=2000 and tornado group by year; +select year, sum(precipitation) from station_data group by year having precipitation>0.5; +select DISTINCT STATION_NUMBER FROM STATION_DATA ORDER BY STATION_NUMBER ASC; From d3394486a158a1247dda2aed635322583bd9d72a Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 14:14:40 +0530 Subject: [PATCH 05/24] Updating readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 64831ff..1230f9d 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -This is only for my practice of the book's examples +# Queries for all the examples chapter-wise + +# Chapter 9 \ No newline at end of file From c96ad64a8303bae752f17ac064784f40bc129379 Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 14:23:02 +0530 Subject: [PATCH 06/24] updating queries --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1230f9d..b7af875 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,20 @@ # Queries for all the examples chapter-wise -# Chapter 9 \ No newline at end of file +## Chapter 4 **SELECT** + +### Retrieving Data +`select * FROM PRODUCT;` + +### Expressions in SELECT statements +`select *,PRICE*1.07 FROM PRODUCT; ` +`select *,PRICE*1.07 AS TAXED_PRICE FROM PRODUCT;` +`select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT;` + +### Describe Table +`pragma table_info('customer');` + +### Text Concatenation +`select name, city||' '||state as location from customer; ` +`select name, region|| ' ' || street_address || ',' || city || ',' || state || ',' || zip as shipping_address from customer;` + +## Chapter 5 **WHERE** From b00cbb3a4184fc37dd5deaddcfeb630d8f0959c9 Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 14:26:19 +0530 Subject: [PATCH 07/24] updating queries --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b7af875..4029b4b 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ `select * FROM PRODUCT;` ### Expressions in SELECT statements -`select *,PRICE*1.07 FROM PRODUCT; ` -`select *,PRICE*1.07 AS TAXED_PRICE FROM PRODUCT;` -`select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT;` +`select *,PRICE*1.07 FROM PRODUCT; +select *,PRICE*1.07 AS TAXED_PRICE FROM PRODUCT; +select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT;` ### Describe Table `pragma table_info('customer');` From 1809aca0a958ebb38458fbe4654888d079fa71b6 Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 14:28:46 +0530 Subject: [PATCH 08/24] updatin queries --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4029b4b..4160c36 100644 --- a/README.md +++ b/README.md @@ -3,18 +3,22 @@ ## Chapter 4 **SELECT** ### Retrieving Data -`select * FROM PRODUCT;` +```sql +select * FROM PRODUCT;``` ### Expressions in SELECT statements -`select *,PRICE*1.07 FROM PRODUCT; +```sql +select *,PRICE*1.07 FROM PRODUCT; select *,PRICE*1.07 AS TAXED_PRICE FROM PRODUCT; -select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT;` +select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT;``` ### Describe Table -`pragma table_info('customer');` +`sql +pragma table_info('customer');` ### Text Concatenation -`select name, city||' '||state as location from customer; ` -`select name, region|| ' ' || street_address || ',' || city || ',' || state || ',' || zip as shipping_address from customer;` +```sql +select name, city||' '||state as location from customer; +select name, region|| ' ' || street_address || ',' || city || ',' || state || ',' || zip as shipping_address from customer;``` ## Chapter 5 **WHERE** From ae099c9f35954a7eed492aa8bbcd44f3eeef1efd Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 14:31:10 +0530 Subject: [PATCH 09/24] updating queries --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4160c36..7cdc795 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,21 @@ ## Chapter 4 **SELECT** ### Retrieving Data -```sql +``` select * FROM PRODUCT;``` ### Expressions in SELECT statements -```sql +``` select *,PRICE*1.07 FROM PRODUCT; select *,PRICE*1.07 AS TAXED_PRICE FROM PRODUCT; select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT;``` ### Describe Table -`sql +` pragma table_info('customer');` ### Text Concatenation -```sql +``` select name, city||' '||state as location from customer; select name, region|| ' ' || street_address || ',' || city || ',' || state || ',' || zip as shipping_address from customer;``` From 759ca31170df230708870048aa115c512b21eeec Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 14:32:21 +0530 Subject: [PATCH 10/24] updatin queries --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7cdc795..6d39b0d 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,24 @@ ### Retrieving Data ``` -select * FROM PRODUCT;``` +select * FROM PRODUCT; +``` ### Expressions in SELECT statements ``` select *,PRICE*1.07 FROM PRODUCT; select *,PRICE*1.07 AS TAXED_PRICE FROM PRODUCT; -select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT;``` +select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT; +``` ### Describe Table -` -pragma table_info('customer');` +```ragma table_info('customer'); +``` ### Text Concatenation ``` select name, city||' '||state as location from customer; -select name, region|| ' ' || street_address || ',' || city || ',' || state || ',' || zip as shipping_address from customer;``` +select name, region|| ' ' || street_address || ',' || city || ',' || state || ',' || zip as shipping_address from customer; +``` ## Chapter 5 **WHERE** From 583d6d34fdcb2433a22e2f349e3bc673e665fcb0 Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 14:32:45 +0530 Subject: [PATCH 11/24] update --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d39b0d..a4982bf 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT; ``` ### Describe Table -```ragma table_info('customer'); +``` +pragma table_info('customer'); ``` ### Text Concatenation From a34873356b8c261ec4ae06022532397a4a93f2c5 Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 15:35:15 +0530 Subject: [PATCH 12/24] updating queries --- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/README.md b/README.md index a4982bf..cf9b34e 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,68 @@ select name, region|| ' ' || street_address || ',' || city || ',' || state || ', ``` ## Chapter 5 **WHERE** +### Using Where on Numbers +``` +select * from station_data where year>2005 and year<2010 ; +select * from station_data where year between 2005 and 2010; +``` +### AND, OR and IN statements +``` +select * from station_data where month=3 or month=6 or month=9 or month=12; +select * from station_data where month in (3,6,9,12); +select * from station_data where month not in (3,6,9,12); +select * from station_data where month%3=0; +``` + +### Using WHERE on Text +``` +select * from station_data where length(report_code)=6; +select * from station_data where report_code like 'b%'; +select * from station_data where report_code like 'b_c%'; +``` + +### Using WHERE on Booleans +``` +select * from station_data where tornado=1 and hail=1; +select * from station_data where tornado and hail; +select * from station_data where tornado=0 and hail; +select * from station_data where not tornado and hail; +``` +### Handling NULL +``` +select * from station_data where snow_depth is NULL; + +//coalesce() function +select report_code, coalesce(precipitation,0) as rainfall from station_data where precipitation <=0.5; +select * from station_data where (rain=1 and temperature<=32) or snow_depth>0; +``` +## Chapter 6 **GROUP BY and ORDER BY** +### Grouping Records +``` +select count(*) from station_data where tornado; +select year, month, count(*) as count from station_data group by year; +// Grouping using ordinal positions +select count(*) from station_data where tornado; +select year, month, count(*) as count from station_data group by 1; +``` +### Ordering Records +``` +select * from station_data where tornado=1 group by 1,2 order by 1,4 desc; +``` +### Aggregate Functions +``` +//sum() function +select year, sum(snow_depth) from station_data where year>=2000 group by year; + +//max() function +select year, sum(snow_depth) as total_snow , sum(precipitation) as total_precipitation, max(precipitation) from station_data where year>=2000 and tornado group by year; +``` +### HAVING Statement +``` +select year, sum(precipitation) from station_data group by year having precipitation>0.5; +``` +### Getting DISTINCT Records +``` +select DISTINCT STATION_NUMBER FROM STATION_DATA ORDER BY STATION_NUMBER ASC; + +``` From f5ad8788624964bc179c3eb9e2b4314a9adbc794 Mon Sep 17 00:00:00 2001 From: Arzoo Bapna <65864642+ar-zoop@users.noreply.github.com> Date: Sat, 21 May 2022 15:35:40 +0530 Subject: [PATCH 13/24] Delete select.txt --- select.txt | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 select.txt diff --git a/select.txt b/select.txt deleted file mode 100644 index 299f701..0000000 --- a/select.txt +++ /dev/null @@ -1,30 +0,0 @@ -select * FROM PRODUCT; -select *,PRICE*1.07 FROM PRODUCT; -select *,PRICE*1.07 AS TAXED_PRICE FROM PRODUCT; -select *,round(PRICE*1.07,0) AS TAXED_PRICE FROM PRODUCT -pragma table_info('customer'); -select name, city||' '||state as location from customer; -select name, region|| ' ' || street_address || ',' || city || ',' || state || ',' || zip as shipping_address from customer; -select * from station_data where year>2005 and year<2010 ; -select * from station_data where year between 2005 and 2010; -select * from station_data where month=3 or month=6 or month=9 or month=12; -select * from station_data where month in (3,6,9,12); -select * from station_data where month not in (3,6,9,12); -select * from station_data where month%3=0; -select * from station_data where length(report_code)=6; -select * from station_data where report_code like 'b%'; -select * from station_data where report_code like 'b_c%'; -select * from station_data where tornado=1 and hail=1; -select * from station_data where tornado and hail; -select * from station_data where tornado=0 and hail; -select * from station_data where not tornado and hail; -select * from station_data where snow_depth is NULL; -select report_code, coalesce(precipitation,0) as rainfall from station_data where precipitation <=0.5; -select * from station_data where (rain=1 and temperature<=32) or snow_depth>0; -select count(*) from station_data where tornado; -select year, month, count(*) as count from station_data group by 1; -select * from station_data where tornado=1 group by 1,2 order by 1,4 desc; -select year, sum(snow_depth) from station_data where year>=2000 group by year; -select year, sum(snow_depth) as total_snow , sum(precipitation) as total_precipitation, max(precipitation) from station_data where year>=2000 and tornado group by year; -select year, sum(precipitation) from station_data group by year having precipitation>0.5; -select DISTINCT STATION_NUMBER FROM STATION_DATA ORDER BY STATION_NUMBER ASC; From 5e763bcd9b46467b024f8ad4e68a3c1f9d262593 Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 16:17:07 +0530 Subject: [PATCH 14/24] updating queries --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/README.md b/README.md index cf9b34e..4deafa9 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ select * from station_data where (rain=1 and temperature<=32) or snow_depth>0; ``` select count(*) from station_data where tornado; select year, month, count(*) as count from station_data group by year; + // Grouping using ordinal positions select count(*) from station_data where tornado; select year, month, count(*) as count from station_data group by 1; @@ -89,5 +90,70 @@ select year, sum(precipitation) from station_data group by year having precipit ### Getting DISTINCT Records ``` select DISTINCT STATION_NUMBER FROM STATION_DATA ORDER BY STATION_NUMBER ASC; +``` + +## Chapter 7 **CASE Statements** +### The CASE Statement +``` +select report_code,year,month,wind_speed, + CASE + when wind_speed>=4 then 'high' + when wind_speed between 3 and 4 then 'moderate' + else 'low' end as wind_severity +from station_data; + +//More efficient method +select report_code,year,month,wind_speed, +CASE + when wind_speed>=4 then 'high' + when wind_speed >=3 then 'moderate' + else 'low' +END AS wind_severity +from station_data; ``` + +### Grouping CASE Statements +``` +select year, +CASE + when wind_speed>=4 then 'high' + when wind_speed >=3 then 'moderate' + else 'low' +END AS wind_severity , +count(*) as count +from station_data +GROUP BY 1,2; +``` + +### The "Zero/Null" CASE Trick +``` +select year, month, +sum(case + when tornado=0 then precipitation + else 0 END) +AS non_tornado_precipitation, +sum(case + when tornado=1 then precipitation + else 0 END) +as tornado_precipitation +from station_data +group by year,month; +``` +``` +select year,month, +max(case when tornado=1 then precipitation else Null end) as max_precipitation_tornado, +max (case when tornado=0 then precipitation else NULL end) as max_precipitation_non_tornado +from station_data +group by year; +``` +``` +select month, +avg(case when rain or hail then temperature else NULL end) as avg_preicpitation_temp, +avg(case when not (rain or hail) then temperature else NULL end) as avg_non_precipitation_temp +from station_data +where year>2000 +group by month +``` + +## Chapter 8 **JOIN** From 7c2c3cb2271a3f8ac2baa26485c9d35fb358c734 Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 16:23:20 +0530 Subject: [PATCH 15/24] updating queries --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4deafa9..406af24 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # Queries for all the examples chapter-wise -## Chapter 4 **SELECT** +# Table of Contents +1. SELECT (#1) +2. WHERE (#2) +3. GROUP BY and ORDER BY +4. CASE Statements +5. JOIN + +## Chapter 4 **SELECT** ### Retrieving Data ``` @@ -25,7 +32,7 @@ select name, city||' '||state as location from customer; select name, region|| ' ' || street_address || ',' || city || ',' || state || ',' || zip as shipping_address from customer; ``` -## Chapter 5 **WHERE** +## Chapter 5 **WHERE** ### Using Where on Numbers ``` select * from station_data where year>2005 and year<2010 ; From f89cf39da3dd2d72674d559d6bf4ac3bccebda9e Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 16:24:20 +0530 Subject: [PATCH 16/24] . --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 406af24..764a269 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ 4. CASE Statements 5. JOIN -## Chapter 4 **SELECT** +## Chapter 4 **SELECT** ### Retrieving Data ``` From d27fb1ff8e36024586b3f7e621f077e0c6c6d381 Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 16:25:47 +0530 Subject: [PATCH 17/24] updatin table of contents --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index 764a269..84316bc 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,5 @@ # Queries for all the examples chapter-wise -# Table of Contents -1. SELECT (#1) -2. WHERE (#2) -3. GROUP BY and ORDER BY -4. CASE Statements -5. JOIN - ## Chapter 4 **SELECT** ### Retrieving Data From 7d116e818bf1ffe1cae6d9faa3323efdb89a450a Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 16:27:11 +0530 Subject: [PATCH 18/24] updating formatting --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 84316bc..62e19eb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Queries for all the examples chapter-wise -## Chapter 4 **SELECT** +#Chapter 4 **SELECT** ### Retrieving Data ``` @@ -25,7 +25,7 @@ select name, city||' '||state as location from customer; select name, region|| ' ' || street_address || ',' || city || ',' || state || ',' || zip as shipping_address from customer; ``` -## Chapter 5 **WHERE** +# Chapter 5 **WHERE** ### Using Where on Numbers ``` select * from station_data where year>2005 and year<2010 ; @@ -92,7 +92,7 @@ select year, sum(precipitation) from station_data group by year having precipit select DISTINCT STATION_NUMBER FROM STATION_DATA ORDER BY STATION_NUMBER ASC; ``` -## Chapter 7 **CASE Statements** +# Chapter 7 **CASE Statements** ### The CASE Statement ``` @@ -156,4 +156,4 @@ where year>2000 group by month ``` -## Chapter 8 **JOIN** +# Chapter 8 **JOIN** From 570da1cae3d01f5c67565e853e2870dcb2dfa84f Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 21 May 2022 16:27:42 +0530 Subject: [PATCH 19/24] updating formatting --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 62e19eb..54aaf32 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Queries for all the examples chapter-wise -#Chapter 4 **SELECT** +# Chapter 4 **SELECT** ### Retrieving Data ``` @@ -61,7 +61,7 @@ select * from station_data where snow_depth is NULL; select report_code, coalesce(precipitation,0) as rainfall from station_data where precipitation <=0.5; select * from station_data where (rain=1 and temperature<=32) or snow_depth>0; ``` -## Chapter 6 **GROUP BY and ORDER BY** +# Chapter 6 **GROUP BY and ORDER BY** ### Grouping Records ``` select count(*) from station_data where tornado; From beb251f435886a7f0dd4d40c4e93f64778451035 Mon Sep 17 00:00:00 2001 From: arzoop Date: Sun, 22 May 2022 16:32:40 +0530 Subject: [PATCH 20/24] updating join queries --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++ tempCodeRunnerFile.cpp | 10 +++++++++ tempCodeRunnerFile.exe | Bin 0 -> 49836 bytes 3 files changed, 57 insertions(+) create mode 100644 tempCodeRunnerFile.cpp create mode 100644 tempCodeRunnerFile.exe diff --git a/README.md b/README.md index 54aaf32..9d705c3 100644 --- a/README.md +++ b/README.md @@ -157,3 +157,50 @@ group by month ``` # Chapter 8 **JOIN** +## INNER JOIN +``` +select order_id, customer.customer_id, order_date, ship_date, name, street_address, street_Address, city, state, zip,product_id, order_qty +from customer inner join customer_order +on customer.CUSTOMER_ID= customer_order.CUSTOMER_ID; +``` +## LEFT JOIN +``` +select order_id, customer_id, order_date, +ship_date, name, street_address, street_Address, +city, state, zip,product_id, order_qty +from customer LEFT join customer_order +on customer.CUSTOMER_ID= customer_order.CUSTOMER_ID; +``` +``` +SELECT ORDER_ID, CUSTOMER_ID,NAME +FROM CUSTOMER LEFT JOIN CUSTOMER_ORDER +ON CUSTOMER.CUSTOMER_ID = CUSTOMER_ORDER.CUSTOMER_ID +WHERE ORDER_ID IS NULL; +``` +## Other JOIN Types +### RIGHT JOIN and OUTER JOIN +Not featured in SQLite due to their highly niche nature. + +## Joining Multiple Tables +``` +SELECT ORDER_ID, customer.CUSTOMER_ID, name, +street_address,city,state,zip,order_date,product_id,description, order_qty +FROM CUSTOMER +INNER JOIN CUSTOMER_ORDER +ON CUSTOMER.CUSTOMER_ID = CUSTOMER_ORDER.CUSTOMER_ID +INNER JOIN PRODUCT +ON CUSTOMER_ORDER.PRODUCT_ID=PRODUCT.PRODUCT_ID ; +``` +``` +SELECT ORDER_ID, customer.CUSTOMER_ID, name, +street_address,city,state,zip,order_date,product_id,description, order_qty, ORDER_QTY*PRICE AS REVENUE +FROM CUSTOMER +INNER JOIN CUSTOMER_ORDER +ON CUSTOMER.CUSTOMER_ID = CUSTOMER_ORDER.CUSTOMER_ID +INNER JOIN PRODUCT +ON CUSTOMER_ORDER.PRODUCT_ID=PRODUCT.PRODUCT_ID ; +``` +## Grouping JOINs +``` + +``` diff --git a/tempCodeRunnerFile.cpp b/tempCodeRunnerFile.cpp new file mode 100644 index 0000000..b456912 --- /dev/null +++ b/tempCodeRunnerFile.cpp @@ -0,0 +1,10 @@ +#include +using namespace std; +#define INF 999 +int V=8; +int dist[8]={INF}; + +int main(){ + + return 0; +} diff --git a/tempCodeRunnerFile.exe b/tempCodeRunnerFile.exe new file mode 100644 index 0000000000000000000000000000000000000000..ce0bfa7ad96614919f4a19433bbc32b61995ea76 GIT binary patch literal 49836 zcmeIb3t$x0**AV>cS9BuvI&HX8g-$ofI>(hM6f|~+mJ|Z<^rhTkjn<5xtYvz5s=VL zl=;@w)YrbRZEY1Vt@ib8?OO|YsSOti`dXV>w5ZggqHYLUsua1&e!u6OnVp?%68-w` z|NSm?U@~)l=Q+=Lp65L0IcLty&J^9)&8&5mdXE){HGn+ahEmQD#{%VaBil3NAgUeaYHc02a@*u%C=mXbL;O#m4& zIJRJq#h!^hY$Lkl>b5q5*3qAK`V+aevy`6XdQmU8VK-=~-a<1i`1K^`lu=6xTRnsm z(t{&7Y8$6h8hE`_HyUEi-87ER$ts&z`e@gRfkILmzf0 z_8YN>ZJ8`Sdv;nXM+)FR>^OGfcRPnde>mN|c|5(J=*aVkZX<_6e>h$GRXok*i`VGx z2$Ap;=#f2pehNRolm0q2x^@nQ{t&-V;vanCJC@|nbvgaa&ldg*V?D}6YYP`%j1x!4 zE2wJC=BTz{@Y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941I zQY#Sp_>_z{LRIlL)#Cscp$adprV&UqoAx;@nm~wo2OpvuJ$T^;x?N$|N5i;B@%psY z7bY9p3e^S&-~zmqN$+qWSwfx%X@+lU9v{Mb8m0m?F=#OQLwJ~`ISX$ICWn2)&5#(L z$3Ly5jTpL2rq7e{@rHlzjh735QwYKW-bYOz^g<&+65}&u!gqCkv`Vj!9HKF6Li&qo zRjr4J=QsNHxL33^<_E3#M%6W0GoG7;iJ^P7gXjf4&nO+>UG3 zA(MoKZn7*|Kvyg@W`;+?A!Y)hAQFmpLk6#*J!m~fy%z2DsGX>IZ};1#%40K>aUm@{dQw&>BJ2GIJ22QM-@q1&sRmD9)d9byI M?YdkH?Y{i~1O(0LGynhq literal 0 HcmV?d00001 From 9277ee7c6b8ce800d88e5fe7cc001e4f05da9fe8 Mon Sep 17 00:00:00 2001 From: arzoop Date: Sun, 22 May 2022 16:49:16 +0530 Subject: [PATCH 21/24] updating join queries --- README.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d705c3..c00c312 100644 --- a/README.md +++ b/README.md @@ -202,5 +202,33 @@ ON CUSTOMER_ORDER.PRODUCT_ID=PRODUCT.PRODUCT_ID ; ``` ## Grouping JOINs ``` - +SELECT ORDER_ID, customer.CUSTOMER_ID, name, +street_address,city,state,zip,order_date,product_id,description, order_qty, sum(ORDER_QTY*PRICE) AS totalRevenue +FROM CUSTOMER +INNER JOIN CUSTOMER_ORDER +ON CUSTOMER.CUSTOMER_ID = CUSTOMER_ORDER.CUSTOMER_ID +INNER JOIN PRODUCT +ON CUSTOMER_ORDER.PRODUCT_ID=PRODUCT.PRODUCT_ID +group by customer.customer_id, name; ``` +``` +SELECT ORDER_ID, customer.CUSTOMER_ID, name, +street_address,city,state,zip,order_date,product_id,description, order_qty, sum(ORDER_QTY*PRICE) AS totalRevenue +FROM CUSTOMER +left JOIN CUSTOMER_ORDER +ON CUSTOMER.CUSTOMER_ID = CUSTOMER_ORDER.CUSTOMER_ID +LEFT JOIN PRODUCT +ON CUSTOMER_ORDER.PRODUCT_ID=PRODUCT.PRODUCT_ID +group by 2,3; +``` +*NOTE*: Upon mixing INNER and LEFT join, INNER will always win and all the NULL values will get filtered out. +``` +SELECT ORDER_ID, customer.CUSTOMER_ID, name, +street_address,city,state,zip,order_date,product_id,description, order_qty, coalesce(sum(ORDER_QTY*PRICE),0) AS totalRevenue +FROM CUSTOMER +left JOIN CUSTOMER_ORDER +ON CUSTOMER.CUSTOMER_ID = CUSTOMER_ORDER.CUSTOMER_ID +LEFT JOIN PRODUCT +ON CUSTOMER_ORDER.PRODUCT_ID=PRODUCT.PRODUCT_ID +group by 2,3; +``` \ No newline at end of file From cd937fc93c1200f9645dd73357eaac38212f74fc Mon Sep 17 00:00:00 2001 From: arzoop Date: Mon, 23 May 2022 23:14:46 +0530 Subject: [PATCH 22/24] created a database and create table queries --- README.md | 69 +++++++++++++++++++++++++++++++++++++++++++++- surgetech_self.db | Bin 0 -> 28672 bytes 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 surgetech_self.db diff --git a/README.md b/README.md index c00c312..ece991b 100644 --- a/README.md +++ b/README.md @@ -231,4 +231,71 @@ ON CUSTOMER.CUSTOMER_ID = CUSTOMER_ORDER.CUSTOMER_ID LEFT JOIN PRODUCT ON CUSTOMER_ORDER.PRODUCT_ID=PRODUCT.PRODUCT_ID group by 2,3; -``` \ No newline at end of file +``` +# CHAPTER 9 **Database Design** +## Creating a New Database and Tables +``` +CREATE TABLE Company ( + Company_Id INTEGER PRIMARY KEY AUTOINCREMENT, + Company_name VARCHAR (30) NOT NULL, + Description VARCHAR (60), + Contact INTEGER (10) NOT NULL +); + +CREATE TABLE Attendees ( + Attendee_Id Integer Primary key autoincrement, + Attendee_Name Varchar (60) NOT NULL, + Phone Integer (10) not null, + Email varchar (60), + VIP boolean default(0) +); + +create table Room ( + Room_Id integer primary key autoincrement, + Floor_No integer not null, + Seat_Capacity integer not null +); + +create table Presentations ( + Presentation_Id Integer primary key autoincrement, + Company_Id integer not null, + Room_Id integer not null, + Start_Time time, + End_Time time, + constraint fk_room + foreign key (room_id) + references room(room_id), + constraint fk_companies + foreign key(company_id) + references company(company_id) +); + +create table Presentation_Attendance ( + Ticket_Id integer primary key autoincrement, + Attendee_Id integer , + Presentation_Id integer, + constraint fk_attendees + foreign key (attendee_id) + references attendees (attendee_id), + constraint fk_presentation + foreign key (presentation_id) + references presentation(presentation_id) + +); + +``` +## Creating Views +``` +CREATE VIEW Presentation_VW AS + SELECT company.company_name AS name, + room.room_id AS room_no, + room.floor_no AS floor_no, + room.seat_capacity AS seat_capacity, + start_time, + end_time + FROM presentations + INNER JOIN + company ON company.company_id = presentations.company_id + INNER JOIN + room ON room.room_id = presentations.room_id; +``` diff --git a/surgetech_self.db b/surgetech_self.db new file mode 100644 index 0000000000000000000000000000000000000000..b18638d57c5e127747f15239dd238f231feb1fd7 GIT binary patch literal 28672 zcmeI#Z*S8$90%}*jRvX%?#Wc4J=pIak!olfLOKaeNR$z{>bkDim7+b0ywruT)Gmn! znuLV5iMMyJY`62#AN@#in#p9&6g_SH+;E)63!+A& z(bOMTf6B|`*UOB)J68IpWV5kz`1PJHb?^2Y4_@B?>;C$^t)DJhf9fnQ2tWV=5P$## zAn?Bzxcuh28{6A=zCZgM@h`)Kr(7teA}NB&yQS>@$nTDQn)Lj4v{XdhBT9M9Lq#pp zS19KTCeC+?dmz}H6HCe5A7?cZDd#)pPY_K_NtP7SDxAeqCV`Nqv`kyYDQ7AO*@A_U zIyZG{5AuqsVu=b=RKAppX_lkbERl0sSmCCvNC=+LM;VE7_#~@j6-hLGUTbC**gcqV zOmjQTrG`cDSG!HOy|?Fl|DxDQ%xkb+rSy=Q2yc4q7IQN0zU=$;Nx5!IUM4<{!c(q- z-jpJt_NnTPL`c|5)w$Tb?Y1{IoXdyVl#TRUn@_Vg8RkhLZ<03Rf4INS7XCn1^CYAqaTdpU)JJCF z@0Sa|oXfI~9^J{h+kW)Oxmx?jf=Y+>ioabOZ>^{pxc$ro(EG84v!CyNJLGbBc?ioO z_0pqk*N*kBrR%Nh>#bWo(m_URZhLFXx%wpwvRtZZl~}I@S3NEQEAw_x!ynuY1M^)r zVM+LbCFK3O+o8eXmhbw=7RB`0>LG79=?&>b%9t}jQ$Ay7 zvGR61t{>1ArMh1B?WRSAUKXAp{@*0SG_<0uX=z1Rwwb2tWYmf2;urKmY;|fB*y_009U<00Izz h!0HR&{J;8hj0hnB0SG_<0uX=z1Rwwb2tWV=e*^OQL}>s3 literal 0 HcmV?d00001 From 2a27c092aac8bd2796081ecf6ded3874d9ef29b3 Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 28 May 2022 18:46:40 +0530 Subject: [PATCH 23/24] Inserting, Deleting, updating,Truncating data --- README.md | 105 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 92 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ece991b..895ace8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Queries for all the examples chapter-wise -# Chapter 4 **SELECT** +# Chapter 4 **SELECT** ### Retrieving Data ``` @@ -25,7 +25,7 @@ select name, city||' '||state as location from customer; select name, region|| ' ' || street_address || ',' || city || ',' || state || ',' || zip as shipping_address from customer; ``` -# Chapter 5 **WHERE** +# Chapter 5 **WHERE** ### Using Where on Numbers ``` select * from station_data where year>2005 and year<2010 ; @@ -263,23 +263,23 @@ create table Presentations ( Start_Time time, End_Time time, constraint fk_room - foreign key (room_id) - references room(room_id), - constraint fk_companies - foreign key(company_id) - references company(company_id) + foreign key (room_id) + references room(room_id), + constraint fk_companies + foreign key(company_id) + references company(company_id) ); create table Presentation_Attendance ( Ticket_Id integer primary key autoincrement, Attendee_Id integer , Presentation_Id integer, - constraint fk_attendees - foreign key (attendee_id) - references attendees (attendee_id), - constraint fk_presentation - foreign key (presentation_id) - references presentation(presentation_id) + constraint fk_attendees + foreign key (attendee_id) + references attendees (attendee_id), + constraint fk_presentation + foreign key (presentation_id) + references presentation(presentation_id) ); @@ -299,3 +299,82 @@ CREATE VIEW Presentation_VW AS INNER JOIN room ON room.room_id = presentations.room_id; ``` + +# CHAPTER 10 **Managing Data** +## Insert +``` +insert into attendee (name) +values('arzoo'); +``` +## Multiple Inserts +``` +insert into attendee(name) +values +('b'), +('c'), +('d'); +``` +## Testing Foreign Keys +### Correcting Mistake- Altering table company to have a foregin key attendee_id +``` +pragma foreign_keys=off; +begin transaction; +alter table company rename to company_old; + +CREATE TABLE company ( + Company_Id INTEGER PRIMARY KEY AUTOINCREMENT, + Company_Name VARCHAR (30) NOT NULL, + Description VARCHAR (60), + Attendee_Id INTEGER NOT NULL + REFERENCES Attendees (Attendee_Id), + CONSTRAINT fk_Attendees FOREIGN KEY ( + Attendee_Id + ) + REFERENCES Attendees (Attendee_Id) +); + +insert into company select * from company_old; +commit; +pragma foreign_keys=on; +``` + +### Testing Foreign Keys +The following snippet throws error : FOREIGN KEY constraint failed +``` +insert into company (company_name, attendee_id) +values ('rexapp solutions', 4); +``` +The following snippet works: +``` +insert into company (company_name, attendee_id) +values ('rexapp solutions', 3); +``` + +## DELETE +It deletes all records +``` +delete from company where description is null; +``` + +## TRUNCATE TABLE +Not supported by sqlite but it is the preferred way of deleting records in MySQL,etc. +``` +TRUNCATE TABLE ATTENDEES; +``` + +## UPDATE +``` +update attendees set email=upper(email), +attendee_name=upper(attendee_name) +``` + +``` +update attendees +set vip=1 +where attendee_id in (1,3); +``` + +## DROP TABLE +``` +drop table company_old; +``` \ No newline at end of file From f67e54645d58d225886e79e3a85919d6d9c45b90 Mon Sep 17 00:00:00 2001 From: arzoop Date: Sat, 28 May 2022 18:47:12 +0530 Subject: [PATCH 24/24] db changes upon running queries --- surgetech_self.db | Bin 28672 -> 32768 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/surgetech_self.db b/surgetech_self.db index b18638d57c5e127747f15239dd238f231feb1fd7..2aa25025a33a495cb6b5163b11849682d2bc7818 100644 GIT binary patch delta 882 zcmZp8z}V2hG(lQWfPsO51BjV`m=TD1C+Zl>3NYyT*YI+5FtD?IVc`3~$HFVm)5vv> z?F+{CeoJ<+1IXU^YjHC%OEW?vlbM&1S)LJQ zUokUCH8cM<2L6Zqr}?)5)vw_95@u#&;Ad3kbe3>-aQAie^wD$n_Z49R3o<%YIUxjD zWf|ER#F@1@9fP9${e`ZzgK32PCIJouHvaP<2sHW#zn-Bk17lHYMPfmLLUDdhDJT$% SnSoA_1o{Q+d?1?_?iBzzFaXd1 delta 135 zcmZo@U}|{4I6+#Fje&uI9f)CoZK95`G#i7Se+@5Ch@I1if!~Sm10M^oJWnInIZmI= zf&!N~xSHzO*+sRrIa)0z|6}uIPtMORNX)C89KpUr2+CH-&r^U2>v2SFKF3wU!qRBX T$UfPPf7d1l4uj1c4nOn(w$>wR