Notice
Recent Posts
Recent Comments
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Tags more
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

๐ŸŒฒ์ž๋ผ๋‚˜๋Š”์ฒญ๋…„

My SQL ๊ณต๋ถ€ 2(ORDER, INSERT, NULL) ๋ณธ๋ฌธ

DataBase

My SQL ๊ณต๋ถ€ 2(ORDER, INSERT, NULL)

JihyunLee 2019. 5. 2. 13:48
๋ฐ˜์‘ํ˜•

ORDER

The ORDER BY keyword is used to sort the result-set in ascending or descending order.

 

๋‚˜๋ผ์ด๋ฆ„ ์ˆœ์œผ๋กœ Customer ํ…Œ์ด๋ธ” ์ •๋ ฌํ•˜๊ธฐ

SELECT * FROM Customer ORDER BY country;

๋‚ด๋ฆผ์ฐจ์ˆœ ์ˆœ์œผ๋กœ Customer ํ…Œ์ด๋ธ” ์ •๋ ฌํ•˜๊ธฐ

SELECT * FROM Customer ORDER BY Country DESC

country ์ด๋ฆ„์œผ๋กœ ์ •๋ ฌํ•œ ๋’ค ๋‹ค์‹œ customer name ์œผ๋กœ ์ •๋ ฌํ•˜๊ธฐ

SELECT * FROM Customer ORDER BY Country, CustomerName

country ์ด๋ฆ„์œผ๋กœ ์ •๋ ฌํ•œ ๋’ค ๋‹ค์‹œ customer name ์€ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๊ธฐ

SELECT * FROM Customer ORDER BY Country ASC,CustomerName DESC

INSERT

The INSERT INTO statement is used to insert new records in a table.

๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค 1. table์˜ attribute๋ฅผ ์ง€์ •ํ•˜์—ฌ ๋„ฃ๋Š” ๊ฒฝ์šฐ, 2. table์˜ attribute ๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š๊ณ  ๋„ฃ๋Š” ๊ฒฝ์šฐ( ์ˆœ์„œ๋Œ€๋กœ Insert ํ•ด์•ผํ•จ)

1.table์˜ attribute ์ง€์ •ํ•˜์—ฌ ๋„ฃ๊ธฐ(๋นˆ ๊ณณ์—๋Š”  NULL ์ด ๋“ค์–ด๊ฐ€๊ฒŒ ๋œ๋‹ค.)

Customer table์—์„œ name, country, city ๋„ฃ๊ธฐ

INSERT INTO Customers(CustomerName, City, Country) VALUES ('Amy', Berlin', 'German');

2. ์ง€์ •ํ•˜์ง€ ์•Š๊ณ  ๋„ฃ๊ธฐ

INSERT INTO Customers VALUES('Amy,'Berlin',Germany');

 

NULL

address ๊ฐ€ Null์ธ ์—†๋Š” tuple ์ฐพ๊ธฐ(WHERE {  } IS NULL)

SELECT CustomerName, Address FROM Customers WHERE address IS NULL

address ๊ฐ€ Null ์ด ์•„๋‹Œ tuple ์ฐพ๊ธฐ(WHERE {  } IS NOT NULL)

SELECT CustomerName, Address From Customers WHERE Address IS NOT NULL

 

๋ฐ˜์‘ํ˜•

'DataBase' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

MySQL ๊ณต๋ถ€5(IN, BETWWEN)  (0) 2019.05.03
MySQL ๊ณต๋ถ€4(LIMIT, MIN, MAX, COUNT, AVG, SUM)  (0) 2019.05.03
My SQL ๊ณต๋ถ€ 3(UPDATE, DELETE)  (0) 2019.05.02
My SQL ๊ณต๋ถ€1(SLEECT, FROM, WHERE)  (0) 2019.05.02