zoukankan      html  css  js  c++  java
  • mybatis 动态Sql的模糊查询

    1 where teacher.tname like concat(concat(#{tName}),'%')

     2:distinct的使用

    下面先来看看例子:

         table
       id name
       1 a
       2 b
       3 c
       4 c
       5 b

    比如我想用一条语句查询得到name不重复的所有数据,那就必须使用distinct去掉多余的重复记录。

    select distinct name from table
    得到的结果是:

       name
       a
       b
       c

    好像达到效果了,可是,我想要得到的是id值呢?改一下查询语句吧:

    select distinct name, id from table

    结果会是:

       id name
       1 a
       2 b
       3 c
       4 c
       5 b

    distinct怎么没起作用?作用是起了的,不过他同时作用了两个字段,也就是必须得id与name都相同的才会被排除。。。。。。。

    select id, distinct name from table   错误的写法。

    最终好用的语句如下:

    select *, count(distinct name) from table group by name

  • 相关阅读:
    angular模板
    Growth: 全栈增长工程师指南
    全栈增长工程师实战
    vue 快速搭建项目 iview
    ng-style
    教程视频链接
    内置对象
    对象—封装、继承
    对象—构造函数
    函数-理论
  • 原文地址:https://www.cnblogs.com/bulrush/p/8926228.html
Copyright © 2011-2022 走看看