use sqldb;
select *
from corp;

select corpname, ceo, estdate
from corp;

select corpname, estdate ,ceo
from corp;

select corpname as 회사명, estdate as edt, ceo as 대표이름
from corp;

select corpname 회사명, estdate edt, ceo 대표이름
from corp;

-- 인물테이블에서 이름, 몸무게 조회
select name , weight , weight - 5 as '감량 몸무게'
from person;

-- 인물테이블 이름 , 팔로워수 를 조회
select name, followers, followers + 800
from person;

-- 인물들의 job 업무를 조회
select job
from person;

select distinct job
from person;

select distinct job, gender
from person;

select *
from person;

-- 인물의 이름, 업무, 별명 조회
select name, job, nickname
from person;

select name, job, nickname
from person
where nickname = null;  -- 데이터 없음

select name, job, nickname
from person
where nickname is null; 

select name, job, nickname
from person
where nickname is not null; 
select name, job, height
from person;
-- 키가 175이상이고 180 이하인 인물의 이름 업무, 키를 조회
select name, job, height
from person
where height >= 175
and height <= 180;

select name, job, height
from person
where height between 175 and 180;

select name, job, height
from person
where height not between 175 and 180;

select name, job, height
from person
where height < 175
or height > 180;

-- 이름이 유길채, 장현 인 인물의 이름, 업무, 별명조회
select name, job, nickname
from person
where name = '유길채'
or name = '장현';

-- 이름이 유길채, 장현, 장보고 인 인물의 이름, 업무, 별명조회
select name, job, nickname
from person
where name = '유길채'
or name = '장현'
or name = '장보고';

select name, job, nickname
from person
where name in ( '유길채',  '장현', '장보고');

-- 업무가 의사, 학생 아닌 인물의 이름, 업무, 키를 조회
select name, job, height
from person
where job not in ('의사', '학생');

select name, job, height
from person
where job <> '의사'
and job <> '학생';

SELECT name, job, height
 FROM person
WHERE name LIKE '장%';

SELECT name, job, height
 FROM person
WHERE name LIKE '장_';

SELECT name, job, height
 FROM person
WHERE name LIKE '%석';

SELECT name, job, height
 FROM person
WHERE name LIKE '%우%';
SELECT name, job, height
 FROM person
WHERE name LIKE '_우%';
SELECT name, nickname
 FROM person;
 
 SELECT name, nickname
 FROM person
 where nickname like '%_%';
 
  SELECT name, nickname
 FROM person
 where nickname like '%x_%' escape 'x';
 
SELECT corpname AS 회사명, ceo AS 대표이름, estdate AS 설립일자
 FROM corp
ORDER BY estdate ;

SELECT corpname AS 회사명, ceo AS 대표이름, estdate AS 설립일자
 FROM corp
ORDER BY 설립일자 DESC ;

SELECT name AS 이름, job AS 업무, height AS 키
 FROM person
ORDER BY job, height DESC ;

SELECT name AS 이름, job AS 업무, height AS 키
 FROM person
ORDER BY 2, 3 DESC ;

-- 인물의 이름, 관련회사번호를 조회
select name as 이름, agencyid as 관련회사번호
from person
order by 2;

select name as 이름, agencyid as 관련회사번호
from person
order by 2 desc;

SELECT name AS 이름, agencyid 관련회사번호
 FROM person
ORDER BY agencyid IS NULL ASC , agencyid DESC ;

SELECT name, height, weight
FROM person
LIMIT 3;

SELECT name, height, weight
FROM person
LIMIT 3, 4;

SELECT name, height, weight
FROM person
ORDER BY height DESC
LIMIT 3;


-- 최연소 인물의 이름, 업무, 생년월일 조회
select name, job, birthdate
from person
order by 3 desc
limit 1;
-- 가장 나이가 많은 인물의 이름, 업무, 생년월일 조회
select name, job, birthdate
from person
order by 3 
limit 1;
 
 
 
