database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
ㆍPostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
PostgreSQL Q&A 10036 게시물 읽기
No. 10036
쿼리문 조언 부탁 드립니다 ㅠ
작성자
김영욱(ywkim06)
작성일
2019-01-24 19:41
조회수
3,505

쿼리문 작성 중입니다 ㅠ 그런데 검색조건이 제대로 나오지 않아 고생이네요 ㅠ 조언 부탁드립니다 ㅠ

디폴트 조건으로는 notice_perm_flag = 'Y' 입니다.(기간이 없고 검색시 무조건 검색)

조건은 notice_period_from와 notice_period_to이 입력되있고 나머지 조건이 null이면 

날짜에 해당하는 내용에 해당하는 리스트가 나와야 합니다. 

나머지 검색조건에서는 타이틀, 컨텐츠, 작성자를 검색시 조건에 해당하는것만 나와야 합니다. 조언 부탁드립니다 ㅠ

SELECT

A.notice_seq, A.notice_title, A.notice_contents, A.notice_importance, A.notice_period_from, A.notice_period_to,

A.notice_perm_flag, A.created_by, A.created_date, A.last_updated_by, A.last_updated_date, B.user_id, B.user_name

FROM tocs_efb_notice A

LEFT JOIN tocs_notam_userinfo B

ON A.created_by = B.user_id

WHERE 1=1

<if test="notice_period_from != null and notice_period_from != ''">

AND A.notice_period_from <![CDATA[<=]]> #{notice_period_to}

</if>

<if test="notice_period_to != null and notice_period_to != ''">

AND A.notice_period_to <![CDATA[>=]]> #{notice_period_from}

</if>

<if test="notice_contents == '' and notice_title != null and notice_title != ''">

AND UPPER(A.notice_title) LIKE CONCAT('%',UPPER(#{notice_title}),'%') 

</if>

<choose>

<when test="notice_contents != null">

AND UPPER(A.notice_contents) LIKE CONCAT('%',UPPER(#{notice_contents}),'%')

</when>

<otherwise>

OR A.notice_perm_flag = 'Y'

</otherwise>

</choose>

<if test="notice_contents == '' and created_by != null and created_by != ''">

AND UPPER(A.created_by) LIKE CONCAT('%',UPPER(#{created_by}),'%')

</if>

<choose>

<when test="notice_contents == '' and created_by == null and notice_title == null">

OR A.notice_perm_flag = 'Y'

</when>

<otherwise>

OR A.notice_perm_flag = 'N'

</otherwise>

</choose>

ORDER BY notice_seq

이 글에 대한 댓글이 총 2건 있습니다.

실 쿼리를 살펴보셔야 할 것 같네요.

mybatis 조건에 따른 실 쿼리가 어떻게 바뀌는지 몰라서 상황을 판단할 수 없네요.

 

김상기(ioseph)님이 2019-01-24 20:00에 작성한 댓글입니다.

mybatis 구문은 잘 모르지만...
1. OR 조건을 왜 주는지 모르겠네요?
  - AND 로 해야 맞는 것 아닌지?
2. from, to 기간 조건은
  - 쿼리 조건은 from, to 서로 교차하여 비교하는 것은 맞게 하셨지만.
  - 다만 프로그램 mybatis 조건까지 교차하셨네요? 거꾸로 하신 듯.
  - mybatis 조건으로 notice_period_from 이 널이 아닐 경우
  - #{notice_period_from} 으로 쿼리 조건을 줘야 하는데 #{notice_period_to} 로 조건 주고 있음.
3. 체크 조건이 너무 복잡해요.
  - 각각의 항목들의 입력여부를 함께 처리하고 있네요.
  - 각각 따로 따로 처리해야 할 것 같아요.

마농(manon94)님이 2019-01-28 13:47에 작성한 댓글입니다.
이 댓글은 2019-01-28 13:56에 마지막으로 수정되었습니다.
[Top]
No.
제목
작성자
작성일
조회
10039복제 구성 시 질문 드립니다. [1]
모모와도도
2019-02-07
3210
10038PostgreSQL9.1 + Pacemaker HA 질문
신동평
2019-02-07
3311
10037PgPool Log(Level) 설정 질문 [2]
신동평
2019-01-31
3502
10036쿼리문 조언 부탁 드립니다 ㅠ [2]
김영욱
2019-01-24
3505
10035array + array 원소들끼리의 합? 가능한가요? [2]
test
2019-01-23
3184
10034pgadmin 3 에서 DB 등록이 되니 않네요 [1]
탁구공
2019-01-20
3287
10033특정 테이블의 테이블스페이스 백업 기능이 있을까요? [4]
모모와도도
2019-01-18
3208
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2023 DSN, All rights reserved.
작업시간: 0.051초, 이곳 서비스는
	PostgreSQL v16.1로 자료를 관리합니다