함수는 특정한 작업을 수행하거나 값을 반환하는 일련의 SQL 문입니다.
1. 수학 함수 : ABS(), CEIL(), FLOOR(), ROUND(), TRUNCATE() 등
2. 문자열 함수 : CONCAT(), LENGTH(), UPPER(), LOWER(), SUBSTR(), REPLACE() 등
3. 날짜 및 시간 함수 : NOW(), CURDATE(), CURTIME(), YEAR(), MONTH(), DAY(), HOUR(), MINUTE(), SECOND(), DATE_FORMAT() 등
4. 조건 함수 : IF(), CASE(), COALESCE() 등
5. 집계 함수 : COUNT(), SUM(), AVG(), MAX(), MIN() 등
샘플 자료(다운로드)
https://drive.google.com/file/d/1e6J4dVbR4fPxYvU1sCQwcqWcvLSBIekJ/view?usp=sharing
employees.zip
drive.google.com
C 드라이버에 employees 폴더를 생성하고 그 폴더에서 바로 압축을 풀어 주세요 (폴더가 하나더 나오면 안됩니다)
명령프롬프트 실행해서 경로 이동 후 C:\employees mysql 서버에 접속해주세요
source employees.sql 엔터
CREATE TABLE userTBL(
username char(3) not null,
birthYear int not null,
addr char(2) not null,
mobile char(10) not null,
primary key(username)
);
CREATE TABLE buyTBL(
username char(3) not null,
prodName char(3) not null,
price int not null,
amount int not null,
foreign key(username) references userTBL(username)
);
insert into userTBL values('이승기', 1987, '서울', '010-1234-1234');
insert into userTBL values('홍길동', 1911, '부산', '010-2222-3333');
insert into userTBL values('이순신', 1999, '대구', '010-3333-4444');
insert into buyTBL values('이승기', '운동화', 50, 1);
insert into buyTBL values('이승기', '노트북', 150, 1);
insert into buyTBL values('홍길동', '책', 10, 5);
insert into buyTBL values('홍길동', '모니터', 200, 2);
insert into buyTBL values('이순신', '청바지', 40, 1);
insert into buyTBL values('이순신', '책', 10, 3);
In aggregated query without GROUP BY, expression
#1 of SELECT list contains nonaggregated column 'shopdb.buyTBL.prodName';
this is incompatible with sql_mode=only_full_group_by
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,
NO_ENGINE_SUBSTITUTION
— 집계 함수 사용 안될 경우 실행 해 주세요
SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES';
'MYSQL' 카테고리의 다른 글
GROUP BY 절 (0) | 2023.03.16 |
---|---|
N : M 관계 (0) | 2023.03.16 |
JOIN 구문 (0) | 2023.03.16 |
1 : 1 관계 (0) | 2023.03.16 |
1 : N 관계와 INSERT 구문 (0) | 2023.03.16 |