일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
- hierarchical_clustering
- list
- len()
- 최솟값
- pandas
- del
- sklearn
- elbow method
- count()
- 최댓값
- numpy
- data
- IN
- analizer
- insert()
- append()
- Machine Learning
- 반복문
- DataAccess
- function
- nan
- dendrogram
- string
- Dictionary
- 분류 결과표
- 덴드로그램
- matplotlib
- Python
- wcss
- DataFrame
- Today
- Total
목록Database/MySQL (23)
개발공부

people 데이터 날짜데이터간의 차이구하기 datediff() birthdate 컬럼과 현재시간의 차이를 구하기 select datediff(now(), birthdate) from people; 날짜데이터간 합 구하기 date_add() birthdate 컬럼의 36일 후 구하기 select date_add(birthdate, interval 36 day) from people; birthdate 컬럼의 28주 후 구하기 select date_add(birthdate, interval 28 week) from people; birthdate 컬럼의 10년 후 구하기 select date_add(birthdate, interval 10 year) from people; + - 연산 birthdate 컬..

예제 people 테이블 예제1. birthdt 에서 시, 분, 초만 가져와 'HH:MM:SS 에 태어났습니다' 형태로 만들기 select date_format(birthdt, '%H:%i:%s 에 태어났습니다.') from people; 예제 2. birthdt 에서 년 월 일 시 분만 가져와'YYYY-MM-DD HH-MM 에 태어났습니다.' 형태로 만들기 select date_format(birthdt, '%Y-%m-%d %H:%i 에 태어났습니다.') from people;

people 테이블 년 가져오기 year() select name, year(birthdate) from people; 월 가져오기 month() select name, day(birthdate) from people; 일 가져오기 day() select name, day(birthdate) from people; 요일 가져오기 dayofweek() 일요일 = 1, 월요일 = 2, 화요일 = 3, 수요일 = 4, 목요일 = 5, 금요일 = 6, 토요일 = 7 select name, dayofweek(birthdate) from people; 요일 이름 가져오기 dayname() select name, dayname(birthdate) from people; 시 가져오기 hour() select name,..

curdate() 현재 날짜를 가져온다. YYYY-MM-DD 형태 select curdate(); curtime() 현재 시간을 가져온다 HH:MM:SS 형태 select curtime(); now() 현재 날짜, 시간을 가져온다. YYYY-MM-DD HH:MM:SS 형태 select now(); curdate(), curtime(), now() 이용해 데이터 추가하기 people 테이블 insert into people (name, birthdate, birthtime, birthdt) values ('Harry', curdate(), curtime(), now()); select * from people;

아래와 같은 형식으로 저장하면 MYSQL에서 시간관련 데이터 타입으로 인식된다. date YYYY-MM-DD time HH:MM:SS datetime YYYY-MM-DD HH:MM:DD 생성 예제 insert into people (name, birthdate, birthtime, birthdt) values ('Padma', '1988-11-11', '10:07:35', '1988-11-11 10:07:35'), ('Larry', '1994-04-22', '04:10:42', '1994-04-22 04:10:42'); select * from people; timestamp 날짜를 숫자로 표현, 1970년 1월 1일 자정을 0으로 시작하여 지금까지 흘러온 초를 뜻한다. 타임 스탬프를 이용해 생성시간, ..

books 테이블 데이터의 개수얻기 count() # books 테이블의 데이터 개수(책의 갯수)는 ??? select count(*) from books; # 유니크한 author_fname 의 갯수는??? select count(distinct author_fname) from books; # 책 제목에 the 가 들어있는 책은 몇개인가? select count(*) from books where title like '%the%'; 컬럼별로 데이터를 묶기 group by # author_lname 별로, 몇권의 책을 썼는지, # author_lname과 cnt라는 컬럼으로 데이터를 가져오기 select author_lname, count(*) as cnt from books group by autho..

books 테이블 1. 원하는 행 가져오기 limit limit number - 처음부터 number만큼의 행 가져오기 limit number1, number2 - number1 부터 number2 개 만큼 가져오기 number1은 0부터 시작한다. books 테이블의 데이터를 3개만 가져오기 select * from books limit 3; 최근 released_year 이 7번째로 작은것부터 3개의 데이터 가져오기 limit 의 offset은 0부터 시작이기 때문에 6으로 작성한다. select * from books order by released_year desc limit 6, 3; 문자열 검색 like title에 'the' 가 들어있는 데이터만 가져오기 select * from books ..

books 테이블 중복 없이 선택하기 distinct author_fname의 이름을 중복없이 가져오기 select distinct author_lname from books; 작가의 full name을 중복없이 가져오기 select distinct concat(author_fname, ' ', author_lname) as full_name from books; 데이터 정렬하기 order by order by 컬럼명 오름차순(디폴트) asc 내림차순 desc sql문의 제일 마지막에 쓴다. title로 정렬하기 -- 오름차순 select * from books order by title; -- 내림차순 select * from books order by title desc; author_lname 으로..

books 테이블 1. 문자열 교체 함수 replace() replace(원본, 교체하고 싶은 문자, 교체 후 문자) title 컬럼에 들어있는 e를 3으로 바꿔서 가져오기. select replace(title, 'e', '3') from books; 2. 문자열의 순서를 거꾸로 바꾸는 함수 reverse() 'author_fname'을 뒤집어서 가져오기 select reverse(author_fname) from books; 3. 문자열의 길이를 구하는 함수 char_length() title의 길이를 구하기 select title, char_length(title) as length from books; 4. 문자열의 대소문자 변경 함수 upper(), lower() title 대문자로 변경 sel..

문자열의 일부분 가져오기 substr(), substring() 두개는 같은 함수이다. substring(컬럼이름, 시작위치(sql은 1부터시작), 끝위치) or substr(컬럼이름, 시작위치(sql은 1부터시작), 끝위치) 아래와 같은 books 테이블이 있다. 1. title을 처음부터 10글자 까지만 가져오기 select substring(title, 1, 10) as title from books; 2. title의 맨 뒤에서 5번째 글자부터 끝가지 가져오기 select substring(title, -5) as title from books; 3. title의 5번째 글자부터 12번째 글자까지 가져오기 select substr(title, 5, 12) as title from books;