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

  • 相关阅读:
    Spring Security配置logout地址
    flex布局
    视口的学习笔记
    box-sizing属性
    css清除浮动
    line-height的理解
    position和float小结
    css居中方法小结
    margin重叠
    浅谈负margin
  • 原文地址:https://www.cnblogs.com/bulrush/p/8926228.html
Copyright © 2011-2022 走看看