나의 발자취
SQL 기본 쿼리 (1) select, from, where, order by, limit, select distinct, is not(<>), union, between, like, and, or 본문
SQL 기본 쿼리 (1) select, from, where, order by, limit, select distinct, is not(<>), union, between, like, and, or
달모드 2024. 9. 11. 16:39select * from customer;
-- as "String"
select cust_id, contact_name, company_name, mileage * 1.1 as "10% 추가" from customer;
select cust_id, contact_name, company_name, mileage from customer where mileage >= 100;
-- order by
-- limit
select cust_id, contact_name, company_name, mileage, city
from customer
where city = '서울'
order by mileage desc
limit 3
-- distinct: 중복된 이름을 제거한 도시를 추출
select distinct city from customer;
SELECT COUNT(DISTINCT city) AS distinct_city_count FROM customer;
-- is not
select * from customer where contact_position <> '대표'
select * from customer where contact_position != '대표'
-- union // 합치면서 중복 제거 (중복된 결과도 출력하려면 union all) - 속성 개수와 타입이 동일해야함.
select cust_id, contact_name, mileage, city from customer where city = '부산'
union
select cust_id, contact_name, mileage, city from customer where mileage < 100;
-- or
select * from customer where contact_position in ('대표','사원');
select * from customer where contact_position = '대표' or contact_position = '사원';
-- between
-- and
select * from customer where mileage between 100 and 200;
select * from customer where mileage = 100 and mileage = 200;
-- like
select * from customer where region like '서울%';
select * from customer where region like '%광역시';
-- 대전, 서울,컨택포지션은 대표나 사원
select * from customer where contact_position in ('대표','사원') and city in ('대전', '서울');
'Backend' 카테고리의 다른 글
node.js 파일 간 함수 전달 (module.exports), 파일 읽고 쓰기 (1) | 2024.09.25 |
---|---|
node.js - npm모듈 설치하기 (0) | 2024.09.24 |
데이터베이스 모델 설계, insert into-do update set (0) | 2024.09.13 |
SQL 기본 쿼리 (2) 숫자 관련 메서드: length(), concat(), left(), right(), split_part(), lpad(), rpad(), trim(), position(), repeat(), replace(), reverse(), 올림/내림/반올림/제곱근/ 절댓값/모듈러/랜덤 (1) | 2024.09.11 |
PostgreSQL로 DB 생성 (0) | 2024.09.11 |