치킨 주문 분석:
https://github.com/JakeOh/20230228_itwill_java140_lab_java/blob/master/lab-oracle/call_chicken.csv
행의 데이터들을 쉼표(,)로 구분해서 표 형태의 데이터를 저장한 텍스트 파일
일반적으로는 구분자로 쉼표(,)를 많이 사용하지만, 이외의 다른 구분자를 사용하기도 한다.
다른 종류의 컴퓨터(OS)들 간에 테이블 형태의 데이터들을 주고받을 때 많이 사용하는 파일 형식.
CREATE TABLE chicken (
calldate DATE,
-- weekday VARCHAR2(10),
call_day VARCHAR2(1 CHAR), --단위가 없으면 1byte, 글자 단위는 char 명시
-- city VARCHAR2(10),
district VARCHAR2(4 CHAR),
-- age VARCHAR2(10),
ages VARCHAR2(5 CHAR),
-- gender VARCHAR2(2),
gender VARCHAR2(1 CHAR),
-- callcount NUMBER(10)
calls NUMBER(4)
);
--> 접속 > 테이블 밑에서 import
ALTER TABLE chicken RENAME COLUMN "기준일" TO calldate;
ALTER TABLE chicken RENAME COLUMN "요일" TO weekday;
ALTER TABLE chicken RENAME COLUMN "시군구" TO city;
ALTER TABLE chicken RENAME COLUMN "연령대" TO age;
ALTER TABLE chicken RENAME COLUMN "성별" TO gender;
ALTER TABLE chicken RENAME COLUMN "통화건수" TO callcount;
COMMIT;
SELECT MAX(callcount), MIN(callcount)
FROM chicken;
SELECT *
FROM chicken
WHERE callcount = (SELECT MIN(callcount) FROM chicken)
OR callcount = (SELECT MAX(callcount) FROM chicken);
SELECT weekday, ROUND(AVG(callcount),2) AS "치킨 주문수"
FROM chicken
GROUP BY weekday
HAVING AVG(callcount) = (SELECT max(avg(callcount)) FROM chicken GROUP BY weekday);
SELECT age, ROUND(AVG(callcount),2) AS "치킨 주문수"
FROM chicken
GROUP BY age
HAVING AVG(callcount) = (select max(avg(callcount)) FROM chicken GROUP BY age)
ORDER BY ROUND(AVG(callcount),2) DESC;
SELECT city, ROUND(AVG(callcount),2) AS "치킨 주문수"
FROM chicken
GROUP BY city
HAVING AVG(callcount) = (select max(avg(callcount)) FROM chicken GROUP BY city)
ORDER BY ROUND(AVG(callcount),2) DESC;
SELECT gender, ROUND(AVG(callcount),2) AS "치킨 주문수"
FROM chicken
GROUP by gender
ORDER BY ROUND(AVG(callcount),2) DESC;
SELECT gender, sum(callcount)
FROM chicken
GROUP BY gender;
SELECT weekday, age, ROUND(AVG(callcount),2) AS "통화건수 평균"
FROM chicken
GROUP BY weekday, age
ORDER BY ROUND(AVG(callcount),2) DESC;
SELECT city, gender, ROUND(AVG(callcount),2) AS "통화건수 평균"
FROM chicken
GROUP BY city, gender
ORDER BY ROUND(AVG(callcount),2) DESC;
SELECT weekday, city, age, ROUND(AVG(callcount),2) AS "통화건수 평균"
FROM chicken
GROUP BY weekday, city, age
ORDER BY ROUND(AVG(callcount),2) DESC;
-- 3 ~ 11 문제의 출력은 통화건수 평균의 내림차순 정렬, 소숫점 2자리까지 반올림.