CREATE SHEMA 'NAME' DEFAULT CHARCTER SET utf8
CREATE TABLE table_name (
id_num INT NOT NULL AUTO_INCREMENT,
mb_id VARCHAR(20),
mb_pw VARCHAR(100),
PRIMARY KEY(seq)
) ENGINE= MYISAM CHARSET=utf8;
INSERT INTO Student (name, birthday)
VALUES ("NAME", "2000-01-01")
insert into Student values (2, "name2", "2010-01-01")
SELECT * FROM Student
SELECT name FROM Student
select * from Student where name = "name1"
select * from Student where name like "na%"
SELECT name FROM Student ORDER BY idx
SELECT name FROM Student ORDER BY idx DESC
UPDATE Student SET Name = 'newName1'
DELETE FROM Student
ALTER TABLE Student ADD COLUMN Height INTEGER
ALTER TABLE Student drop COLUMN Height
DROP TABLE Student
SELECT Name AS "이름", Birthday AS "생일" FROM Student;
SELECT Name "이름", Birthday "생일" FROM Student;
CREATE VIEW Birthday
AS
SELECT
Name,
Birthday bdate,
substr(Birthday, 1, 4) YYYY,
substr(Birthday, 6, 2) MM,
substr(Birthday, 9, 2) DD
FROM Person;
DROP VIEW Birthday
SELECT
Name,
bdate,
MM,
CASE
WHEN MM = '01' THEN 'Jan.'
WHEN MM = '02' THEN 'Feb.'
WHEN MM = '03' THEN 'Mar.'
WHEN MM = '04' THEN 'Apr.'
WHEN MM = '05' THEN 'May.'
WHEN MM = '06' THEN 'Jun.'
WHEN MM = '07' THEN 'Jul.'
WHEN MM = '08' THEN 'Aug.'
WHEN MM = '09' THEN 'Sep.'
WHEN MM = '10' THEN 'Oct.'
WHEN MM = '11' THEN 'Nov.'
WHEN MM = '12' THEN 'Dec.'
END Month
FROM Birthday;
SELECT round(Height), count(*)
FROM Person
GROUP BY 1;
SELECT round(Height), count(*)
FROM Person
GROUP BY 1;
HAVING count(*) > 1;
round(123.4567, 2) : 123.5
substr('abcdefg', 3) : 3번째 자리 부터 끝까지
substr('abcdefg', 3, 2) : 3번짜 자리부터 두 글자
count(*) : 모든 행 수를 센다.
count(컬럼명) : 해당 컬럼에 데이터가 있는 행을 센다.
max()
min()
sum(컬럼명)
avg(컬럼명)