회원가입 테이블
일정화면 테이블
내가 팔로잉한 친구들의 일정을 가져오는 테이블
테이블을 만들었으면 임의의 더미 데이터로 테스트 해본다.
여기서 데이터는 가지고 있다고 가정하고 아래와 같은 sql문을 작성할 수 있다.
여기서 Foreign Key 설정에 관해 다루지는 않았지만 했다고 가정한다.
-- 1. 회원가입 sql을 작성.
insert into user ( email, password, nickname)
values ('abc@naver.com', 'abcd1234', '홍길동');
-- 2. 25개씩 가장 먼 미래의 일정부터 차례로 보여줍니다.
-- 나는 user_id 1번인 사람이다 라고 가정.
select *
from schedule
where user_id = 1
order by date desc
limit 0,25;
-- 3. 일정 작성하는 sql
insert into schedule ( user_id, content, date)
values ( 101 , "일요일에 맛있는 저녁", "2025-07-2 13:25:30") ;
-- 4. 일정완료 버튼을 누르면, 일정 완료시키는 SQL
update schedule
set is_completed = 1
where id = 1002;
-- 5. 친구들의 일정목록 가져오는 SQL
-- 내 아이디는 1이다라고 가정하고 만든다.
-- 현재시간 기준으로, 지나지 않은 일정을 가져온다.
select s.user_id, s.content, s.date, s.created_at, f.followee_id, s.is_completed
from follow f
join schedule s
on f.followee_id = s.user_id
join user u
on u.id = f.followee_id
where f.follower_id= 1 and s.date > now()
order by s.date desc
limit 0,25 ;
-- 현재시간 이전의 지난 일정을 가져온다.
select s.user_id, s.content, s.date, s.created_at, f.followee_id, s.is_completed
from follow f
join schedule s
on f.followee_id = s.user_id
join user u
on u.id = f.followee_id
where f.follower_id= 1 and s.date < now()
order by s.date desc
limit 0,25 ;
'AWS > MySQL' 카테고리의 다른 글
MySQL 영화 리뷰 서비스 개발 (0) | 2022.12.12 |
---|---|
MySQL 인스타그램 클론 스키마 디자인 (0) | 2022.12.12 |
MySQL sns 테이블 생성 : 좋아요, 팔로우, 태그 등은 유니크해야한다. (0) | 2022.12.08 |
MySQL 테이블 합치기 left join on, Foreign keys, n번 고객이 주문한 데이터 가져오기, 다른테이블에 남은 고객정보 한번에 삭제하기 on delete cascade (0) | 2022.12.08 |
MySQL !=, group by having, between A and B, not like, case, if ,not in, not null (0) | 2022.12.07 |