mysql - 两表关联查询,按条件筛选结果
PHPz
PHPz 2017-04-17 16:24:02
[MySQL讨论组]

有如下两张表

tb_test_paper

字段:test_time , applicant_id

tb_applicant

字段id , id_card(不唯一) , check_status , data_3

其中上表applicant_id与下表id关联

问题:两表关联查询,idCard为传入参数,查询出满足下面三种条件的信息,sql该怎么写?在mybatis中怎么写?

1.id_card=idCard check_status=0

2.id_card=idCard check_status=1 data_3=0

3.id_card=idCard check_status=1 data_3=1 test_time>系统当前时间

PHPz
PHPz

学习是最好的投资!

全部回复(1)
怪我咯
<select parameterType="map">
    select * from tb_test_paper tp, tb_applicant ta
    <where>
        tp.applicant_id = ta.id
        <if test="check_status != null and check_status !='' ">
            and ta.check_status = #{check_status }
        </if>
        <if test="data_3 != null and data_3 !=''">
            and ta.data_3= #{data_3}
        </if>
        <if test="test_time != null and test_time !=''">
            and tp.test_time= #{test_time}
        </if>
    </where>
</select>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号