select sClass 班级,count(*) 班级学生总人数, sum(case when sGender=0 then 1 else 0 end) 女生人数, sum(case when sGender=0 then 1 else 0 end)*1.0/count(*)女生所占比例, sum(case when sGender=1 then 1 else 0 end) 男生人数, sum(case when sGender=1 then 1 else 0 end)*1.0 /coun
step1:在mysql cmd中新建存储过程: drop procedure if exists queryCountByGrade ; delimiter // -- 定义存储过程结束符号为// create procedure queryCountByGrade(IN gradenameinput INT(),OUT counts ) begin select count(*) into counts from student where grade = gradenameinput;en
--创建视图 create view StuClassView as SELECT s.ID ,s.StuName ,s.StuAge ,s.StuAddress ,s.StuTel ,s.ClassId ,s.StuId,s.StuSex ,e.ClassName,e.ClassInfo,e.ClassFlag FROM Classes as e left join Students as s on s.ClassId=e.ClassId end) as '男', end) as '女' fr
先说下问题产生的背景: 最近在做一个用到MyBatis的项目,其中有个业务涉及到关联查询,我是将两个查询分开来写的,即嵌套查询,个人感觉这样更方便重用: 关联的查询使用到了动态sql,在执行查询时就出现了如下错误:Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'id' in 'class java.lang.Integer' 因为出现了这个问题,
Ibatis/Mybatis模糊查询 根据网络内容整理 Ibatis中 使用$代替#.此种方法就是去掉了类型检查,使用字符串连接,不过可能会有sql注入风险. Sql代码 select * from table1 where name like '%$name$%' 使用连接符.不过不同的数据库中方式不同. mysql: select * from table1 where name like concat('%', #name#, '%') oracle: select * from tabl
Mybatis模糊查询的实现不难,如下实例:在UserMapper.xml中根据用户名模糊查询用户: <!-- 模糊查询用户 --> <select id="findSomeUser" resultMap="userResultMap" parameterType="java.lang.String"> SELECT * FROM user WHERE username LIKE CONCAT('%',#{value},'
oracle count 百万级 分页查询记录总数.总条数优化 oracle count 百万级 查询记录总数.总条数优化 最近做一个项目时,做分页时,发现分页查询速度很慢,分页我做的是两次查询,一次是查询总数,一次是查询分页结果 /** 查询总记录数 **/ SELECT COUNT(id) FROM USER order by id /** 查询结果集 **/ select * from ( select row_.*, rownum rownum_ from ( select id , u
原文地址:http://lavasoft.blog.51cto.com/62575/1386870 Mybatis like查询官方文档没有明确的例子可循,网上搜索了很多,都不正确. Mybatis 3.2.6 经过尝试,给出三种可靠可用的写法: select * from person where name like "%"#{name}"%" select * from person where name like '%'||#{name}||'%' sel