선릉역 1번 출구
SQL Database(DML) 본문
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
1. select
- select column1, column2 ... from 테이블 이름 where 조건;
or
- select * from 테이블 이름 where 조건; (모든 열)
*distinct속성: select distinct column from 테이블 이름;
= column에서 중복 값은 제외하고 select
where 조건
1. =
2. >, <, >=, <=, <>(not equal)
3. BETWEEN: select * from 테이블 이름 where 열 이름 between 값1 and 값2;
값1 <= 열 이름 <= 값2
https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_between
4. LIKE: select * from 테이블 이름 where 이름 like 패턴;
%:여러 글자, _:한글자
ex) select * from student where name like 'c%u' :c로 시작해 u로 끝나는 아무 이름
SymbolDescriptionExample
% | Represents zero or more characters | bl% finds bl, black, blue, and blob |
_ | Represents a single character | h_t finds hot, hat, and hit |
[] | Represents any single character within the brackets | h[oa]t finds hot and hat, but not hit |
^ | Represents any character not in the brackets | h[^oa]t finds hit, but not hot and hat |
- | Represents any single character within the specified range | c[a-b]t finds cat and cbt |
5. IN: select * from 테이블 이름 where 열 이름 in (값, 값); or select * from 테이블 이름 where 열 이름 in (select statement);
6. AND, OR, NOT
where 구문은 and, or, not이랑 combine될 수 있음
1. select * from 테이블 이름 where 조건1 AND 조건2;
2. select * from 테이블 이름 where 조건1 OR 조건2;
3. select * from 테이블 이름 where NOT 조건;
order by
결과 값을 오름차순으로 정렬하냐 내림차순으로 정렬하냐의 차이
-select * from 테이블 이름 where 조건 order by 열 이름 asc|desc; //오름차순이 default값
열 이름1, 열 이름2 -> 열 이름1의 같은 값은 열 이름2에 의해 정렬됨
https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_orderby2
SQL Tryit Editor v1.6
WebSQL stores a Database locally, on the user's computer. Each user gets their own Database object. WebSQL is supported in Chrome, Safari, Opera, and Edge(79). If you use another browser you will still be able to use our Try SQL Editor, but a different ver
www.w3schools.com
-select * from 테이블 이름 where 조건 order by 열이름1 asc|desc 열이름2 asc|desc;
is null
where 열 이름 is null | is not null
https://www.w3schools.com/sql/trysql.asp?filename=trysql_is_null
SQL Tryit Editor v1.6
WebSQL stores a Database locally, on the user's computer. Each user gets their own Database object. WebSQL is supported in Chrome, Safari, Opera, and Edge(79). If you use another browser you will still be able to use our Try SQL Editor, but a different ver
www.w3schools.com
limit(select되는 것의 출력 상위 개수 지정)
-select * from 테이블 이름 where 조건 limit 개수;
min, max, avg, count, sum
- select min/max/avg/count/sum(열 이름) from 테이블 이름 where 조건;
+ select min/max/avg/count/sum(열 이름) as 새로 출력될 열 이름 from 테이블 이름 where 조건;
alias
1. 컬럼 as
SELECT column_name AS alias_name FROM table_name;
2. 테이블 as
SELECT column_name(s) FROM table_name AS alias_name;
group by
특정 컬럼을 그룹화
https://extbrain.tistory.com/56
[MySQL] 그룹화하여 데이터 조회 (GROUP BY)
▶MySQL 그룹화하여 데이터 조회 (GROUP BY) ▶설명 하나, 예를 들어보겠습니다. MySQL에서 유형별로 갯수를 가져오고 싶은데, 단순히 COUNT 함수로 데이터를 조회하면 전체 갯수만을 가져옵니다. 이렇
extbrain.tistory.com
having
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
2. update
- update 테이블 이름 set 열1=값, 열2=값, ... where 조건;
UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;
3. insert into
- insert into 테이블 이름 (열1, 열2, ...) values (값1, 값2,...);
4. delete
- delete from 테이블 이름 where 조건;
'Hacking & Security > 자격증' 카테고리의 다른 글
SQL Database(DCL) (0) | 2022.05.03 |
---|---|
SQL Database(DML) - join (0) | 2022.05.03 |
SQL Database(DDL) (0) | 2022.05.03 |
정처기 실기 9. 소프트웨어 개발 보안 구축(1) (0) | 2022.05.02 |
정처기 실기 요약 사이트 모음집 (0) | 2022.05.02 |