• 双表的增删改查-sql语句


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
    <mapper namespace="com.lzl.dao.DoctorDao">

    <select id="findAll" resultType="doctor">

    select d.*,c.pname as sname, cc.pname as cname,
    ccc.pname as xname, de.kname as kname,
    DATEDIFF(d.birthday,d.rzdate) as gl, GROUP_CONCAT(s.sname) as scname
    from doctor d left JOIN city c on d.province=c.id
    LEFT JOIN city cc ON d.town=cc.id
    LEFT JOIN city ccc ON d.county=ccc.id
    LEFT JOIN department de on d.desk=de.id
    LEFT JOIN guanxi g on d.adept=g.mid
    left JOIN shanchang s on g.fid=s.id

    <where>
    1=1
    <!-- 姓名模糊查询 -->
    <if test="name!='' and name!=null">
    AND d.name like '%${name}%'
    </if>
    <!-- 性别下拉框查询 -->
    <if test="grader!=0">
    AND d.grader =#{grader}
    </if>
    <!-- 省市区三级联动查询 -->
    <if test="province!=0">
    AND d.province = #{province}
    </if>
    <if test="town!=0">
    AND d.town = #{province}
    </if>
    <if test="county!=0">
    AND d.county = #{county}
    </if>
    <!-- 根据科室id查找 -->
    <if test="desk!=0">
    AND d.desk = #{desk}
    </if>
    <!-- 年龄从小到大查询 -->
    <if test="MinAge!=0">
    AND d.age >= #{MinAge}
    </if>
    <if test="MaxAge!=0">
    AND d.age &lt;= #{MaxAge}
    </if>
    </where>
    GROUP BY d.id
    </select>
    <select id="findProvince" resultType="doctor">

    SELECT id,pname as sname from city WHERE pid=0

    </select>
    <select id="findDepart" resultType="doctor">

    select * from department

    </select>
    <select id="findTown" resultType="doctor" >
    SELECT id,pname as sname from city WHERE pid= #{id}
    </select>
    <select id="findById" resultType="doctor" >
    select d.*,c.pname as sname,
    cc.pname as cname,
    ccc.pname as xname,
    de.kname as kname,DATEDIFF(d.birthday,d.rzdate) as gl,
    GROUP_CONCAT(s.sname) as scname
    from doctor d left JOIN city c on d.province=c.id
    LEFT JOIN city cc ON d.town=cc.id
    LEFT JOIN city ccc ON d.county=ccc.id
    LEFT JOIN department de on d.desk=de.id
    LEFT JOIN guanxi g on d.adept=g.mid
    left JOIN shanchang s on g.fid=s.id where d.id=#{id}
    </select>
    <select id="findByShanChang" resultType="doctor" >
    select * from shanchang
    </select>
    <delete id="deleteGuanXi">
    delete from guanxi where mid=#{adept}
    </delete>
    <insert id="addGuanXi">
    insert into guanxi values(#{adept},#{i})
    </insert>
    <update id="update">
    update doctor set name=#{name},`rzdate`=#{rzdate},
    birthday=#{birthday},grader=#{grader},province=#{province},
    town=#{town},county=#{county},desk=#{desk},adept=#{adept},
    touxiang=#{touxiang} where id=#{id}
    </update>
    <insert id="add" useGeneratedKeys="true" keyColumn="id" keyProperty="id" >
    insert into doctor(`name`,`rzdate`,`birthday`,`grader`,`province`,`town`,`county`,`desk`,`touxiang`,`sfz`,`telephone`,`age`) values(#{name},#{rzdate},#{birthday},#{grader}
    ,#{province},#{town},#{county},#{desk},#{touxiang},#{sfz},#{telephone},DATEDIFF(#{birthday},#{rzdate}))
    </insert>
    <update id="addAdept">
    update doctor set adept=#{id} where id=#{id}
    </update>
    </mapper>

  • 相关阅读:
    为什么我的Android SDK Manager中只显示已安装的package?
    解决Android Studio Gradle Build特别慢的问题
    一款不错的取色器
    Android Studio没有导包快捷键怎么办
    Android Studio中有没有类似于Eclipse中的ctrl+2+L的快捷键? Android Studio快捷键之代码提示
    安卓动画总结【非原创】
    ButterKnife-5.1.2.jar(较低版本的ButterKnife)使用方法
    【转】调用getActionBar()报Call requires API level 11 (current min is 8): android.app.Activity#getActionBar
    spring容器加载完毕做一件事情(利用ContextRefreshedEvent事件)转
    详解 Spring 3.0 基于 Annotation 的依赖注入实现(转)
  • 原文地址:https://www.cnblogs.com/liuzhaolong/p/12874599.html
Copyright © 2020-2023  润新知