묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
데이터베이스 조인 관련
2007.12.20 10:13
일정관리 게시판을 만들려고 하는데, 음력을 DB에 저장해 놓고 게시판의 extra_vars들과 조인해서 사용하려고 합니다.
혹시 쿼리 XML을 만들때 조인 관련 형식은 어떻게 되는지 알 수 있을까 해서 이렇게 글을 남깁니다.
비교식(condition) 에서 조인해서 2개의 칼럼을 사용하는 방법하구요, 칼럼비교시 변수가 아니라 query에 상수를 집어넣는 방법을 알려주시면 감사하겠습니다.
아래와 같은 방법으로 사용할수는 없는 거겠죠 ^^
<query id="getDocumentList" action="select">
<tables>
<table name="documents" alias="b" />
<table name="stdt" alias="a" />
</tables>
<columns>
<column name="a.stdt01" alias="yymmdd" />
<column name="a.week01" alias="ww" />
<column name="a.yun" alias="yun" />
<column name="a.lstdt" alias="lu" />
<column name="b.*" />
</columns>
<conditions>
<condition operation="in" column="b.module_srl" var="module_srl" filter="number" />
<condition operation="equal" column="b.category_srl" var="category_srl" pipe="and" />
<!-- adsf -->
<group pipe="and">
<group>
<condition operation="equal" column="substring(b.extra_vars1,5,4)" column="substring(a.lstdt,5,4)"/>
<condition operation="equal" column="b.extra_vars2" value="음력" pipe="and" />
<condition operation="equal" column="b.extra_vars3" value="반복" pipe="and" />
<condition operation="less" column="substring(b.extra_vars1,1,4)" column="substring(a.lstdt,1,4)" pipe="and" />
</group>
<group pipe="or">
<condition operation="equal" column="substring(b.extra_vars1,5,4)" column="substring(a.stdt01,5,4)"/>
<condition operation="notequal" column="b.extra_vars2" value="음력" pipe="and" />
<condition operation="equal" column="b.extra_vars3" value="반복" pipe="and" />
<condition operation="less" column="substring(b.extra_vars1,1,4)" column="substring(a.lstdt,1,4)" pipe="and" />
</group>
<group pipe="or">
<condition operation="equal" column="substring(b.extra_vars1,5,4)" column="substring(a.lstdt,5,4)"/>
<condition operation="equal" column="b.extra_vars2" value="음력" pipe="and" />
<condition operation="notequal" column="b.extra_vars3" value="반복" pipe="and" />
<condition operation="equal" column="substring(b.extra_vars1,1,4)" column="substring(a.lstdt,1,4)" pipe="and" />
</group>
<group pipe="or">
<condition operation="equal" column="substring(b.extra_vars1,5,4)" column="substring(a.stdt01,5,4)"/>
<condition operation="notequal" column="b.extra_vars2" value="음력" pipe="and" />
<condition operation="notequal" column="b.extra_vars3" value="반복" pipe="and" />
<condition operation="equal" column="substring(b.extra_vars1,1,4)" column="substring(a.lstdt,1,4)" pipe="and" />
</group>
</group>
<group pipe="and">
<condition operation="equal" column="b.member_srl" var="s_member_srl" pipe="or" />
</group>
<group pipe="and">
<condition operation="more" column="a.stdt01" var="start_date" pipe="and" />
<condition operation="less" column="a.stdt01" var="end_date" pipe="and" />
</group>
</conditions>
<navigation>
<index var="sort_index" default="list_order" order="order_type" />
</navigation>
</query>
혹시 쿼리 XML을 만들때 조인 관련 형식은 어떻게 되는지 알 수 있을까 해서 이렇게 글을 남깁니다.
비교식(condition) 에서 조인해서 2개의 칼럼을 사용하는 방법하구요, 칼럼비교시 변수가 아니라 query에 상수를 집어넣는 방법을 알려주시면 감사하겠습니다.
아래와 같은 방법으로 사용할수는 없는 거겠죠 ^^
<query id="getDocumentList" action="select">
<tables>
<table name="documents" alias="b" />
<table name="stdt" alias="a" />
</tables>
<columns>
<column name="a.stdt01" alias="yymmdd" />
<column name="a.week01" alias="ww" />
<column name="a.yun" alias="yun" />
<column name="a.lstdt" alias="lu" />
<column name="b.*" />
</columns>
<conditions>
<condition operation="in" column="b.module_srl" var="module_srl" filter="number" />
<condition operation="equal" column="b.category_srl" var="category_srl" pipe="and" />
<!-- adsf -->
<group pipe="and">
<group>
<condition operation="equal" column="substring(b.extra_vars1,5,4)" column="substring(a.lstdt,5,4)"/>
<condition operation="equal" column="b.extra_vars2" value="음력" pipe="and" />
<condition operation="equal" column="b.extra_vars3" value="반복" pipe="and" />
<condition operation="less" column="substring(b.extra_vars1,1,4)" column="substring(a.lstdt,1,4)" pipe="and" />
</group>
<group pipe="or">
<condition operation="equal" column="substring(b.extra_vars1,5,4)" column="substring(a.stdt01,5,4)"/>
<condition operation="notequal" column="b.extra_vars2" value="음력" pipe="and" />
<condition operation="equal" column="b.extra_vars3" value="반복" pipe="and" />
<condition operation="less" column="substring(b.extra_vars1,1,4)" column="substring(a.lstdt,1,4)" pipe="and" />
</group>
<group pipe="or">
<condition operation="equal" column="substring(b.extra_vars1,5,4)" column="substring(a.lstdt,5,4)"/>
<condition operation="equal" column="b.extra_vars2" value="음력" pipe="and" />
<condition operation="notequal" column="b.extra_vars3" value="반복" pipe="and" />
<condition operation="equal" column="substring(b.extra_vars1,1,4)" column="substring(a.lstdt,1,4)" pipe="and" />
</group>
<group pipe="or">
<condition operation="equal" column="substring(b.extra_vars1,5,4)" column="substring(a.stdt01,5,4)"/>
<condition operation="notequal" column="b.extra_vars2" value="음력" pipe="and" />
<condition operation="notequal" column="b.extra_vars3" value="반복" pipe="and" />
<condition operation="equal" column="substring(b.extra_vars1,1,4)" column="substring(a.lstdt,1,4)" pipe="and" />
</group>
</group>
<group pipe="and">
<condition operation="equal" column="b.member_srl" var="s_member_srl" pipe="or" />
</group>
<group pipe="and">
<condition operation="more" column="a.stdt01" var="start_date" pipe="and" />
<condition operation="less" column="a.stdt01" var="end_date" pipe="and" />
</group>
</conditions>
<navigation>
<index var="sort_index" default="list_order" order="order_type" />
</navigation>
</query>