Mybatis查询返回多个sum、count数据解决方案
来源:互联网 发布:淘宝店铺招牌怎么做 编辑:程序博客网 时间:2024/06/07 04:50
前言:
对于sum,count这种数据多个进行查询输出,mybatis应该如何对应输出?
示例:
以下数据进行Mybatis输出,输出3个sum结果:
select sum(case when status = #{status1} then 1 else 0 end) count1 , sum(case when status = #{status2} then 1 else 0 end) count2 , sum(case when status = #{status3} then 1 else 0 end) count3 , count(*) count4 from tb_article
注:case when 不明白可以参考:
http://blog.csdn.net/ink4t/article/details/77624299
解决以上情况可使用通用的Map集合来解决:
// mapper.xml内容如下:<select id="findArticleSumAll" resultType="Map"> select sum(case when status = #{status1} then 1 else 0 end) count1 , sum(case when status = #{status2} then 1 else 0 end) count2 , sum(case when status = #{status3} then 1 else 0 end) count3 , count(*) count4 from tb_article </select>
// mapper.java内容如下:Map<String, Integer> findArticleSumAll(@Param("status1") int status1, @Param("status2") int status2, @Param("status3") int status3);
如果需要获取结果直接使用 map.get(“status1”) 即可。
阅读全文
1 0
- Mybatis查询返回多个sum、count数据解决方案
- mybatis使用group by返回sum,count数据
- mybatis使用group by返回sum,count数据
- 使用mybatis,在添加数据的时候返回主键,当查询count和属性字段怎么接收返回数据
- mybatis查询count返回 <== Row: 0
- mybatis 关联查询只返回一条数据
- Mybatis 查询数据返回基本类型数组
- Mybatis 传入多个参数查询数据 (3种方法)
- Hibernate count和sum查询
- springMVC+mybatis查询数据,返回resultType=”map”时,如果数据为空的字段,则该字段省略不显示的解决方案
- mybatis 映射一对多查询返回集合
- MyBatis----多表查询返回包装类
- Mybatis关联查询一对多使用插件分页返回数据不对
- mybatis查询如何返回List<Map>类型数据
- mybatis 查询 resultMap="" 只返回一条数据
- mybatis查询返回空,SQL数据库执行有数据!
- mybatis查询如何返回List<Map>类型数据
- mybatis多条件的模糊查询解决方案
- 匈牙利入门--poj 3020最小路径
- 刷CCF的算法题(第十二天)
- /home/hadoop/app/hadoop/bin/hdfs: line 206: /home/hadoop/app/hadoop/bin/java: No such file or direct
- 【c++】二叉搜索树的插入、查找、非递归删除
- 【安卓学习笔记】JAVA基础Lesson9-对象的转型
- Mybatis查询返回多个sum、count数据解决方案
- FormData多图片上传(每次只能传送最后一张图片的问题)
- pivot行转列函数
- JAVA线程之Volidate与锁机制详解
- 关于分布式事务、两阶段提交协议、三阶提交协议
- 微信聊天开头
- Vi兼容模式
- Linux系统下的web项目环境搭建
- [BZOJ4316]小C的独立集-圆方树-动态规划