DB | [SQL] SQL 실습 내용

bubblegum·2024년 2월 16일
0

DB

목록 보기
3/11
post-thumbnail
  1. 가장 최근에 작성된 게시글 5개의 제목과 내용을 조회
    select title, content
    from post 
    order by created_at desc
    limit 5;
  2. HTTP REST API "GET/ api/posts?orderBy=created_at&orderMethod=ASC"
    select * 
    from post 
    order by created_at asc
  3. 게시글 내용에 "독서"라는 text가 포함된 게시글의 모든 내용(속성)을 조회
    -- like '문자열' - '와일드 카드' % include
    -- % 어떤 값이 와도 된다.
    select * 
    from post
    where content like '%독서%'
  4. 포스트 아이디 1, 2, 3번의 모든 댓글 조회
    select *
    from comment
    where post_id in (2, 3, 4)
  5. alice 라는 사람이 단 모든 댓글 개수 조회
    select count(*)
    from comment
    where user_id = (
        select user_id
        from user
        where username = 'Alice'
    );
    --스칼라 쿼리?
    -- sub query : sql query 안에 존재하는 sql query; 속성 값이 일치해야 함
profile
황세민

0개의 댓글