日期:2014-05-19  浏览次数:20893 次

SQL 查询语句解读 !!在线等待!!
<!-- 考生基本信息 -->
  <select id="qryKssj" resultType="hashmap" parameterType="map">
select 
A.KS_H as KSH,
A.ZJH as ZJH,
A.XM as XM,
A.CYM as CYM,
XB.MC as XB,
MZ.MC as MZ,
A.JG as JG,
to_char(A.CSRQ, 'yyyy-mm-dd') as CSRQ,
A.LXDH as LXDH,
A.TXDZ as TXDZ,
A.YZBM as YZBM,
A.EMAIL as EMAIL,
BMD_MSS.MC as BMD,
A.SJ as SJ,
A.YBM_H as YBMH,
A.TXZ as TXZ,
to_char(A.BYSJ, 'yyyy-mm-dd') as BYSJ,
ZX_MSS.YWMC||decode(trim(ZX_MSS.MC), '', '', '('||trim(ZX_MSS.MC)||')') as BYXX,
WHCD_MSS.MC as WHCDH,
KSLB_MSS.MC as KSLBH,
KSLX.MC as KSLXH
from 
LQ_KSDA_MSS B, KS_MSS A 
left join KSLX on trim(A.KSLX_H) = trim(KSLX.KSLX_H)
left join BMD_MSS on trim(A.BMD_H) = trim(BMD_MSS.BMD_H)
left join WHCD_MSS on trim(A.WHCD_H) = to_char(WHCD_MSS.WHCD_H)
left join XB on A.XB_H = XB.XB_H
left join KSLB_MSS on trim(A.KSLB_H) = trim(KSLB_MSS.KSLB_H)
left join MZ on trim(A.MZ_H) = trim(MZ.MZ_H)
left join ZX_MSS on trim(A.BYXX) = trim(ZX_MSS.ZX_H)
where
B.KS_H = A.KS_H
and B.TDYX_H = #{yxH,jdbcType=VARCHAR}
<if test="isqrlq == 1">
and B.ISQRLQ = 1
</if>
<if test="kslxH != null">
and A.KSLX_H = #{kslxH,jdbcType=INTEGER}
</if>
order by A.KS_H
  </select>





谁能帮我解读一下 前提是本人没有学过SQL ,我想知道 谁指的是“表”

谁指的是 字段 还有里面的逻辑 越详细越好 在线等!!谢谢各位

------解决方案--------------------
只要理解表的查询最终都是从一个表中查询,这个表可以原始表,也可以是按各种条件连接之后的虚拟表
------解决方案--------------------
<select id="qryKssj" resultType="hashmap" parameterType="map">
select //语法 select 字段 from 表名 where 条件 
A.KS_H as KSH,//查询KS_MSS表中的KS_H字段,后面的 ksh是 这个字段的别名 下面都一样
A.ZJH as ZJH,
A.XM as XM,
A.CYM as CYM,
XB.MC as XB,
MZ.MC as MZ,
A.JG as JG,
to_char(A.CSRQ, 'yyyy-mm-dd') as CSRQ,//时间格式转换输出
A.LXDH as LXDH,
A.TXDZ as TXDZ,
A.YZBM as YZBM,
A.EMAIL as EMAIL,
BMD_MSS.MC as BMD,
A.SJ as SJ,
A.YBM_H as YBMH,
A.TXZ as TXZ,
to_char(A.BYSJ, 'yyyy-mm-dd') as BYSJ,
ZX_MSS.YWMC||decode(trim(ZX_MSS.MC), '', '', '('||trim(ZX_MSS.MC)||')') as BYXX, //decode 就像if else decode('如果','数据','否则数据')//表达能力不好、你google一下decode就好
WHCD_MSS.MC as WHCDH,
KSLB_MSS.MC as KSLBH,
KSLX.MC as KSLXH
from 
LQ_KSDA_MSS B, KS_MSS A 
left join KSLX on trim(A.KSLX_H) = trim(KSLX.KSLX_H)//同理、、你查吧、google 一下 ‘sql中多表联查’
left join BMD_MSS on trim(A.BMD_H) = trim(BMD_MSS.BMD_H)
left join WHCD_MSS on trim(A.WHCD_H) = to_char(WHCD_MSS.WHCD_H)
left join XB on A.XB_H = XB.XB_H
left join KSLB_MSS on trim(A.KSLB_H) = trim(KSLB_MSS.KSLB_H)
left join MZ on trim(A.MZ_H) = trim(MZ.MZ_H)
left join ZX_MSS on trim(A.BYXX) = trim(ZX_MSS.ZX_H)
where
B.KS_H = A.KS_H
and B.TDYX_H = #{yxH,jdbcType=VARCHAR}
<if test="isqrlq == 1"><!--拼接的sql 如果.....-->
and B.ISQRLQ = 1
</if>
<if test="kslxH != null">
and A.KSLX_H = #{kslxH,jdbcType=INTEGER}
</if>
order by A.KS_H
</select>
好了、、、、、、这个sql是生成的???????、