[MySQL] LIKE (% / _) / NOT LIKE + ฮฑ
18 Nov 2021 -
1 minute read
LIKE / NOT LIKE + WILDCARD (%, _)
-
LIKE %
SELECT column_name1 FROM table_name WHERE column_name2 LIKE '๋ฌธ์์ด'; SELECT column_name1 FROM table_name WHERE column_name2 LIKE '๋ฌธ์์ด%'; SELECT column_name1 FROM table_name WHERE column_name2 LIKE '%๋ฌธ์์ด%'; SELECT column_name1 FROM table_name WHERE column_name2 LIKE '%๋ฌธ์์ด';
-
LIKE _
SELECT column_name1 FROM table_name WHERE column_name2 LIKE '___';
-
์ธ๋์ค์ฝ์ด n๊ฐ > ์ปฌ๋ผ์ ๊ฐ์ด 3์๋ฆฟ์์ธ๊ฒ๋ง ์ถ๋ ฅ
-
๋ฌธ์์ด ์ค๊ฐ์ ์ฌ์ฉ ๊ฐ๋ฅ
-
-
NOT LIKE
- ํน์ ๋ฌธ์์ด์ ์ ์ธํ ๊ฒ์
SELECT column_name1 FROM table_name WHERE column_name2 NOT LIKE '๋ฌธ์์ด';
-
โ%โ๋ โ_โ์ด ๋ค์ด๊ฐ ๋ฌธ์์ด์ ์ฐพ๊ณ ์ถ๋ค๋ฉด ๋ฐฑ์ฌ๋์ ์ฌ์ฉ (โ
%\%%
โ / โ%\_%
โ)
SOURCE
-
์ธ๋ถ sql ํ์ผ์ ์์ฑํ ์ฟผ๋ฆฌ ์คํํ๊ธฐ
SOURCE ํ์ผ๊ฒฝ๋ก/ํ์ผ์ด๋ฆ.sql
COUNT
-
๋ฐ์ดํฐ ๊ฐ์ ๊ตฌํ๊ธฐ
SELECT COUNT(*) FROM table_name; SELECT COUNT(column_name) FROM table_name; SELECT COUNT(DISTINCT column_name) FROM table_name;
UPPER / LOWER / REVERSE
-
๋๋ฌธ์๋ก ์ถ๋ ฅํ๊ธฐ
SELECT UPPER();
-
์๋ฌธ์๋ก ์ถ๋ ฅํ๊ธฐ
SELECT LOWER();
-
๋ฌธ์์ด ๋ฐ๋๋ก ์ถ๋ ฅํ๊ธฐ
SELECT REVERSE('๋ฌธ์์ด');
CHAR_LENGTH
-
๋ฌธ์์ด์ ๊ธธ์ด ๊ตฌํ๊ธฐ
SELECT CHAR_LENGTH('๋ฌธ์์ด'); SELECT CHAR_LENGTH(column_name);
MIN / MAX
-
์ต๋/์ต์๊ฐ ์ถ๋ ฅํ๊ธฐ
SELECT MIN(column_name) FROM table_name; SELECT MAX(column_name) FROM table_name; SELECT column_name1, column_name2 MIN(column_name3) FROM table_name GROUP BY column_name1, column_name2; SELECT * FROM table_name WHERE column_name = (SELECT MIN(column_name) FROM table_name);
SUM / AVG
-
ํฉ๊ณ ์ถ๋ ฅ
SELECT SUM(column_name) FROM table_name;
-
ํ๊ท ์ถ๋ ฅ
SELECT AVG(column_name) FROM table_name;
ROUND / FLOOR / CEIL
-
ROUND() : ๋ฐ์ฌ๋ฆผ
-
FLOOR() : ๋ด๋ฆผ
-
CEIL() : ์ฌ๋ฆผ
-
ex)
create table member( ... age int, ... ); select concat(round(avg(age)), '์ธ') ํ๊ท ๋์ด from member;