카테고리 없음

스파르타 AI-8기 TIL(9/22)

kimjunki-8 2024. 9. 22. 20:53

DB -> DataBase = In short, it's a big folder storing data

SELECT/FROM

select * -> used when getting the data. used to all the Query viewing data

from food_orders 

* -> Bring all the column

from-> statement to specify the table when bringing data


Selecting necessary parts of the column

select restaurant_name, addr

from food_orders

 

select (specific name of the column), (specific name of the column), ....

from (table)

 

Changing the name of the column

To:

select (name of the column) as (changed name), (name of the column) (changed name)

 

2 ways to change the name

1. (name of the column) as (changed name)

2. (name of the column) (changed name) -> don't use "as"

 

The point when changing the name

1. English or underbar

Just write as usual -> orb_yes

2. Other language(Korean) or Special characters

Must be covered with "" -> "특수문자"


If searching only certain data under condition, (where)

select *

from customers

WHERE age = 21

for gender,

select *

from customers

WHERE gender = 'male' -> Since male itself is not a column, but a text, it must be covered with "" 

 

WHERE (condition) = 

 

Other ways of filtering methods(Comparison operation, BETWEEN, IN, LIKE)

Comparison operation

=  -> same Ex. gender = "female"

 <> not same (different) Ex. gender <> "female"

> big Ex. age > 21

>= same or big Ex. age >= 21

< small Ex. age < 21

<= same or small Ex. age <= 21

 

BETWEEN -> It brings all the data between A and B

IN -> adding the condition" including"

LIKE -> not exactly same but adding the similar data condition

 

Ex. BETWEEN

Frame - WHERE (table) between (condition) and (condition)

WHERE age between 21 and 23 -> getting the column from age, and bring all the data between 21 ~ 23

 

Ex. IN

Frame - WHERE (table) in ((condition)) -> must covered by ()

WHERE age in (21, 25, 27) -> only gets the data where the ages are 21, 25, 27

 

Ex.LIKE
Frame
-

1. If it starts with specific start text -> WHERE (table) like '(starting text)%'

2. If it includes a special text -> WHERE (table) like '%including text%'

3. If it ends with specific text -> WHERE (table) like %(starting text)'

Ex. 1

 

Ex. 2

 

Ex. 3

 

Multiple Condition(and, or, not)

 

AND

select *

from customers c

WHERE age >= 21

and gender = 'male'

and -> It will make all the condition statements work together

OR

 

select *

from customers c

WHERE age >= 21

or gender = 'male'

Or -> will show all the data that satisfied any of the condition

 

 

NOT

 

select *

from customers c

WHERE not gender = 'male'

not = same as <>

 

Good night!