📅2024. 02.14 45일차
# reactionPoint(추천) 테이블 생성
CREATE TABLE reactionPoint (
id INT(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
regDate DATETIME NOT NULL,
updateDate DATETIME NOT NULL,
memberId INT(10) UNSIGNED NOT NULL,
relTypeCode CHAR(50) NOT NULL COMMENT '관련 데이터 타입 코드',
relId INT(10) UNSIGNED NOT NULL COMMENT '관련 데이터 번호',
`point` SMALLINT(2) NOT NULL
);
# reactionPoint 테스트 데이터 생성
# 1번 회원이 1번 글에 싫어요
INSERT INTO reactionPoint
SET regDate = NOW(),
updateDate = NOW(),
memberId = 1,
relTypeCode = 'article',
relId = 1,
`point` = -1;
# 1번 회원이 2번 글에 좋아요
INSERT INTO reactionPoint
SET regDate = NOW(),
updateDate = NOW(),
memberId = 1,
relTypeCode = 'article',
relId = 2,
`point` = 1;
# 2번 회원이 1번 글에 싫어요
INSERT INTO reactionPoint
SET regDate = NOW(),
updateDate = NOW(),
memberId = 2,
relTypeCode = 'article',
relId = 1,
`point` = -1;
# 2번 회원이 2번 글에 싫어요
INSERT INTO reactionPoint
SET regDate = NOW(),
updateDate = NOW(),
memberId = 2,
relTypeCode = 'article',
relId = 2,
`point` = -1;
# 3번 회원이 1번 글에 좋아요
INSERT INTO reactionPoint
SET regDate = NOW(),
updateDate = NOW(),
memberId = 3,
relTypeCode = 'article',
relId = 1,
`point` = 1;
@Select("""
SELECT A.*, M.nickname AS extra__writer,
IFNULL(SUM(RP.point),0) AS extra__sumReactionPoint,
IFNULL(SUM(IF(RP.point > 0, RP.point, 0)),0) AS extra__goodReactionPoint,
IFNULL(SUM(IF(RP.point < 0, RP.point, 0)),0) AS extra__badReactionPoint
FROM article AS A
INNER JOIN `member` AS M
ON A.memberId = M.id
LEFT JOIN reactionPoint AS RP
ON A.id = RP.relId AND RP.relTypeCode = 'article'
WHERE A.id = #{id}
GROUP BY A.id
""")
public Article getForPrintArticle(int id);
@Select("""
<script>
SELECT A.*, M.nickname AS extra__writer,
IFNULL(SUM(RP.point),0) AS extra__sumReactionPoint,
IFNULL(SUM(IF(RP.point > 0, RP.point, 0)),0) AS extra__goodReactionPoint,
IFNULL(SUM(IF(RP.point < 0, RP.point, 0)),0) AS extra__badReactionPoint
FROM article AS A
INNER JOIN `member` AS M
ON A.memberId = M.id
LEFT JOIN reactionPoint AS RP
ON A.id = RP.relId AND RP.relTypeCode = 'article'
WHERE 1
<if test="boardId != 0">
AND A.boardId = #{boardId}
</if>
<if test="searchKeyword != ''">
<choose>
<when test="searchKeywordTypeCode == 'title'">
AND A.title LIKE CONCAT('%',#{searchKeyword},'%')
</when>
<when test="searchKeywordTypeCode == 'body'">
AND A.body LIKE CONCAT('%',#{searchKeyword},'%')
</when>
<otherwise>
AND A.title LIKE CONCAT('%',#{searchKeyword},'%')
OR A.body LIKE CONCAT('%',#{searchKeyword},'%')
</otherwise>
</choose>
</if>
GROUP BY A.id
ORDER BY A.id DESC
<if test="limitFrom >= 0 ">
LIMIT #{limitFrom}, #{limitTake}
</if>
</script>
""")
public List<Article> getForPrintArticles(int boardId, int limitFrom, int limitTake, String searchKeywordTypeCode,
String searchKeyword);
[select]
select [X.인사말]
from [테이블X] X
inner join [테이블Y] Y on X.[국가코드] = Y.[국가코드]
where Y.[언어코드] = 'EN'
[update]
update [테이블X] X
inner join [테이블Y] Y on X.[국가코드] = Y.[국가코드]
set [X.인사말] = '변경할 인사말'
where Y.[언어코드] = 'EN'