[MySQL] 多대多관계, null인 데이터를 가져오는 법
MANY : MANY 다 대 다 관계 해당 데이터에 foreign key를 연결해준다. 테이블 reviewer, series, reviews 상기 이미지처럼 생성 및 foreign key 적용 하기 데이터 입력 use yh_db; INSERT INTO series (title, released_year, genre) VALUES ('Archer', 2009, 'Animation'), ('Arrested Development', 2003, 'Comedy'), ("Bob's Burgers", 2011, 'Animation'), ('Bojack Horseman', 2014, 'Animation'), ("Breaking Bad", 2008, 'Drama'), ('Curb Your Enthusiasm', 2000..
더보기
[MySQL] if() 함수, ifnull() 함수 , 실습 풀이
use yh_db; select * from yh_db.books; use yh_db; select * from books; if() 함수 -- pages가 300보다 크면 long, 그렇지 않으면 short -- if( 조건, 조건이 맞으면~하겠다,조건이 맞지 않으면 ~하겠다. ) ㄴ 첫번째 파라미터: 컬럼이름 및 조건 , ㄴ 두번째 파라미터 : ~하겠다 ㄴ 세번째 파라미터: 그렇지 않으면~하겠다. select *, if( pages >=300, 'long','short') as 'long/short' from books; select * from people; insert into people (first_name) values ('Mike'); ifnull() 함수 -- null이라는 값이 있으면,..
더보기
[MySQL] ~인것 가져오기: where, and, or, between…and, in(), case when …then.. else… end
~인것 가져오기 : where, and, or, between…and, in(), case when …then.. else… end -- 오늘 가장 중요한 이야기. -- ~인것 가져오기 -- 연도가 2017인 데이터를 가져오시오 select * from books where released_year = 2017; select * from books where released_year = 2010; -- 년도가 2017년이 아닌 데이터만 가져오시오. select * from books where released_year != 2017; -- author_lname이 Harris가 아닌 데이터만 가져오시오. select * from books where author_lname != 'Harris'; sele..
더보기
[MySQL] 시간 계산: datediff(), date_add(), interval + 시간
desc people2; insert into people2 (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 people2; select name, year(birthdate) from people2; 해당 컬럼의 년도를 보여줌 select name, month(birthdate) from people2; 해당 컬럼의 월를 보여줌 select name, day(birthdate) from people2; 해당 컬럼의 날짜를 보여줌 select nam..
더보기