岁月如灬风 2019-10-28 10:16 采纳率: 0%
浏览 275
已采纳

sql语句问题。。。。。。。。。。。。。。。。。。。

    <select id="findTpostSkillresultListBySpostid" resultClass="tpostSkillresultBean" parameterClass="map" remapResults="true">
        select s.capgrade,
               (select codename from tb_tpost_code where id = s.mpostid) mpostname,
               (select codename from tb_tpost_code where id = s.spostid) spostname,
               r.id,r.username, r.idcard, to_char(r.scoredate, 'yyyy-mm-dd') scoredate, r.score,
               (select ut.sortname from pxgl_unit ut where ut.unitid = r.unitid) unitname_,
               r.remark, r.flowsta, r.chksign, r.noexamsign,
               mainusername estauser,
               to_char(r.estatime,'yyyy-mm-dd') estatime,
               i.itemname,
               (select capgrade from tb_tpost_userpost 
                        where mpostid = s.mpostid and spostid = s.spostid and idcard = r.idcard) usercapgrade
          from tb_tpost_skillresult  r,
               tb_tpost_skillitem    i,
               tb_tpost_skillstandar s
         where (
                (r.noexamsign = 1 and to_char(r.estatime, 'yyyy') = #year#) or
                to_char(scoredate, 'yyyy') = #year#
               )
           and i.standarid = s.id
           and i.id = r.yitemid
           and i.flowsta = 99
           and i.chksign = 1
            <isNotEmpty prepend="and" property="itemid">
                i.id = #itemid#
            </isNotEmpty>
            <isNotEmpty prepend="and" property="flowsta">
                 (r.flowsta >= #flowsta#
                <isNotEmpty prepend="or" property="flowsign">
                        r.flowsta = #SKILLFLOW_DXGSRZ_SH#
                </isNotEmpty>
                )
            </isNotEmpty>
                <isNotEmpty prepend="and" property="waitsign">
                    r.flowsta = #flowsta#
                </isNotEmpty>
           <isNotEmpty property="unitid">
                 and r.unitid in ($unitid$)
           </isNotEmpty>
            <isNotEmpty prepend="and" property="mpostid">
                 s.mpostid = #mpostid#
            </isNotEmpty>
            <isNotEmpty prepend="and" property="spostid">
                 s.spostid = #spostid#
            </isNotEmpty>
            <isNotEmpty prepend="and" property="capgrade">
                 s.capgrade = #capgrade#
            </isNotEmpty>
            <isNotEmpty prepend="and" property="keyword">
                (
                    r.username like '%'||#keyword#||'%'
                 or r.idcard like '%'||#keyword#||'%'
                 or to_char(r.scoredate, 'yyyy-mm-dd') like '%'||#keyword#||'%'
                )
            </isNotEmpty>
        order by s.mpostid, s.spostid, s.capgrade,i.id,r.flowsta
    </select>

原先代码如上,原谅我是个菜鸟,问下如何将以下代码加入到上面代码中。。。

            <isNotEmpty property="capgradeflag">
                <isEqual prepend="and" property="capgradeflag" compareValue="1"> capgrade = (select capgrade from tb_tpost_userpost where mpostid = s.mpostid and spostid = s.spostid and idcard = r.idcard)</isEqual>
                <isEqual prepend="and" property="capgradeflag" compareValue="2"> nvl(capgrade, 0) != nvl((select capgrade from tb_tpost_userpost where mpostid = s.mpostid and spostid = s.spostid and idcard = r.idcard), 0)</isEqual>
            </isNotEmpty>

拜托了。。。

  • 写回答

1条回答 默认 最新

  • renkai721 2019-10-28 11:08
    关注

    加入的代码如下,你试试。

    <select id="findTpostSkillresultListBySpostid" resultClass="tpostSkillresultBean" parameterClass="map" remapResults="true">
            select s.capgrade,
                   (select codename from tb_tpost_code where id = s.mpostid) mpostname,
                   (select codename from tb_tpost_code where id = s.spostid) spostname,
                   r.id,r.username, r.idcard, to_char(r.scoredate, 'yyyy-mm-dd') scoredate, r.score,
                   (select ut.sortname from pxgl_unit ut where ut.unitid = r.unitid) unitname_,
                   r.remark, r.flowsta, r.chksign, r.noexamsign,
                   mainusername estauser,
                   to_char(r.estatime,'yyyy-mm-dd') estatime,
                   i.itemname,
                   (select capgrade from tb_tpost_userpost 
                            where mpostid = s.mpostid and spostid = s.spostid and idcard = r.idcard) usercapgrade
              from tb_tpost_skillresult  r,
                   tb_tpost_skillitem    i,
                   tb_tpost_skillstandar s
             where (
                    (r.noexamsign = 1 and to_char(r.estatime, 'yyyy') = #year#) or
                    to_char(scoredate, 'yyyy') = #year#
                   )
               and i.standarid = s.id
               and i.id = r.yitemid
               and i.flowsta = 99
               and i.chksign = 1
                <isNotEmpty prepend="and" property="itemid">
                    i.id = #itemid#
                </isNotEmpty>
                <isNotEmpty prepend="and" property="flowsta">
                     (r.flowsta >= #flowsta#
                    <isNotEmpty prepend="or" property="flowsign">
                            r.flowsta = #SKILLFLOW_DXGSRZ_SH#
                    </isNotEmpty>
                    )
                </isNotEmpty>
                    <isNotEmpty prepend="and" property="waitsign">
                        r.flowsta = #flowsta#
                    </isNotEmpty>
               <isNotEmpty property="unitid">
                     and r.unitid in ($unitid$)
               </isNotEmpty>
                <isNotEmpty prepend="and" property="mpostid">
                     s.mpostid = #mpostid#
                </isNotEmpty>
                <isNotEmpty prepend="and" property="spostid">
                     s.spostid = #spostid#
                </isNotEmpty>
                <isNotEmpty prepend="and" property="capgrade">
                     s.capgrade = #capgrade#
                </isNotEmpty>
                <isNotEmpty prepend="and" property="keyword">
                    (
                        r.username like '%'||#keyword#||'%'
                     or r.idcard like '%'||#keyword#||'%'
                     or to_char(r.scoredate, 'yyyy-mm-dd') like '%'||#keyword#||'%'
                    )
                </isNotEmpty>
    
                            <!-- 加入的代码 begin -->
                            <isNotEmpty property="capgradeflag">
                    <isEqual prepend="and" property="capgradeflag" compareValue="1"> capgrade = (select capgrade from tb_tpost_userpost where mpostid = s.mpostid and spostid = s.spostid and idcard = r.idcard)</isEqual>
                    <isEqual prepend="and" property="capgradeflag" compareValue="2"> nvl(capgrade, 0) != nvl((select capgrade from tb_tpost_userpost where mpostid = s.mpostid and spostid = s.spostid and idcard = r.idcard), 0)</isEqual>
                </isNotEmpty>
                            <!-- 加入的代码 end -->
    
            order by s.mpostid, s.spostid, s.capgrade,i.id,r.flowsta
        </select>
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题