#Chapter VII of @OReillyMedia Learning SQL book - Data Generation, Manipulation, Conversion
note, this is a long chapter, so I divided it. Let's start
1. Working with string data (today's posts).
3 types of string;
- CHAR - 255 chars
- VARCHAR - 65K chars
- TEXT - see chapter II thread, can store up to 4 GB of data
2. the difference between them is only the stored char length, so keep Length restrictions in your mind.
Additional info, check sql_mode
3. Quotes
We can't use " ' " for quotes in SQL. However, there is a way to use them.
4. CHAR() function to get special characters such as ö,ç,ı
SELECT CHAR(128,129......)
5. LOCATE() function to find chars in string
6. STRCMP() function
Checks the position for the statements.
-1 if first statement is before the second
0 if they are the same
1 if the second statement is before the first
7. LIKE and REGEXP
Common used string expressions. finds the names ending with 'y'
Of course there are too many other string manipulation methods. see the documentation for these, and also leetcode and hackerrank challenges.
See you tomorrow.
• • •
Missing some Tweet in this thread? You can try to
force a refresh
1. GROUP BY is one of the most fundamental functions in #MySQL or any kind. It helps us to retrieve counts, distinct values and etc by certain categorical data.
An example:
2. If you need to filter your tables while using GROUP BY, generally you cannot use WHERE clause, instead use HAVING.
In this example we filtered the data after creating groups. If we'd have used WHERE before GROUP BY, server will raise an error.
First, let's select data for the queries. I'll go with my Coffee Quality repo, the data is from @KaggleDatasets, you can access it there.
Now, back to Chapter.
This chapter is basically about #MySQL statements. It covers select, from, where, group by, order by and having.
2⃣ But first, it would be better to understand how SQL Server executes your queries. When we run a query, the server checks 3 things:
▶️ Permission to execute query
▶️ Permission to access database
▶️ Statement syntax
2⃣ #MySQL Datatypes 1. Character data:
☑️ Fixed-length : right-pinned with spaces
☑️ Variable length : not padded, space consumption varies
i.e : char(20) - fixed ; varchar(20) variable length examples.
3⃣ Character Sets are used for different languages with different letters
Returns a table with different char sets. If maxlen bigger than 1, the chars in that language are bigger than 1 bytes.
A quick note before starting, check @levikul09 for statistics and python related information.
These tweets are my notes from @OReillyMedia#LearningSQL book chapter 1. All the credit goes to that book.
2⃣What is a database? Why it is important in data world?
Well this is easy to answer, there are nearly 2.5 quintillion bytes of data created every day. So it is crucial that this data stored in someplace. That place is called a Database, a set of related information.
2
3⃣Today we are using Relational Database model most of the time. Before, there were Non-Relational Systems:
☑️Hierarchical Database Systems - same as Decision Trees
☑️Network Database Systems - sets of records and sets of link that defines the relationship