m0_60983761 2022-04-03 11:41 采纳率: 89.5%
浏览 59
已结题

java mybatis mysql多条件模糊查询怎么实现

多表 多字段模糊查询 一个查询 匹配作者名或帖子名 或论坛名 这个改怎么实现 不使用es的情况下 sql怎么实现

  • 写回答

3条回答 默认 最新

  • 嘉祐-小萝卜算子 2022-04-03 12:37
    关注

    SELECT
    a.id AS "id",
    a.forum_id AS "forumId",
    a.title AS "tzTitle", //想要模糊查询的字段
    a.content AS "content",
    a.author_id AS "authorId",
    a.create_by AS "createBy.id",
    a.create_date AS "createDate",
    a.update_by AS "updateBy.id",
    a.update_date AS "updateDate",
    a.del_flag AS "delFlag",
    a.dznum AS "dznum",
    a.plnum AS "plnum",
    a.boutique AS "boutique",
    u.NAME AS "authorName", //想要查询的字段
    a.bq_id AS "bqId",
    b.NAME AS "bqName",
    t.title AS "talktitle", //想要模糊查询的字段
    a.talk_id AS "talkId",
    u.photo AS "photo",
    f.title AS "title",
    a.scnum AS "scnum",
    f.tznum AS "tznum",
    d.dz_num AS "zzdznum",
    d.ft_num AS "zzftnum",
    u.company_id AS "companyid",
    a.posttype AS "postType"
    FROM
    lt_posts a
    LEFT JOIN sys_user u ON u.id = a.author_id
    LEFT JOIN lt_bq b ON b.id = a.bq_id
    LEFT JOIN lt_talk t ON t.id = a.talk_id
    LEFT JOIN lt_forum f ON f.id = a.forum_id
    LEFT JOIN lt_author_dsg d ON d.author_id = a.author_id
    WHERE
    a.del_flag = 0
    AND a.posttype = '2'
    AND a.forum_id = “1"
    And (a.title like concat(‘%’,#{keywords},’%’) or u.name like concat(‘%’,#{keywords},’%’) or t.title like concat(‘%’,#{keywords},’%’) )
    ORDER BY
    a.update_date DESC
    LIMIT 5

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 4月11日
  • 已采纳回答 4月3日
  • 创建了问题 4月3日

悬赏问题

  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥15 怎么实现输入一个要删除的数后删除后显示剩余数再输入再删除显示剩余数(语言-c语言)
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection