catfishlyf 2019-08-12 22:03 采纳率: 33.3%
浏览 1914
已结题

mybatis plus同时foreach同一个list的sql该怎么写

我想通过SQL统计各个状态的数据,效果如下:
图片说明

我现在能写出查单条统计结果的sql

SELECT
    a.present_dept_id,
    sum(case when a.create_time is not null and a.add_dept_id='16bf41e8252c0a8c85ed00001' then 1 else 0 end) as createCount, 
    sum(case when a.state = 1 and a.add_dept_id='16bf41e8252c0a8c85ed00001' then 1 else 0 end) as notCreateCount, 
    sum(case when a.state = -1 and a.present_dept_id='16bf41e8252c0a8c85ed00001' then 1 else 0 end) as ignoreCount,
    sum(case when b.dispose_type = 2 and a.present_dept_id='16bf41e8252c0a8c85ed00001' then 1 else 0 end) as dealCount,
    sum(case when a.state = 3 and a.present_dept_id='16bf41e8252c0a8c85ed00001' then 1 else 0 end) as noNealCount,
    sum(case when a.state = 9 and a.present_dept_id='16bf41e8252c0a8c85ed00001' then 1 else 0 end) as deleteCount,
    sum(case when b.dispose_dept_id='16bf41e8252c0a8c85ed00001' and b.target_dept_id!='16bf41e8252c0a8c85ed00001' and b.dispose_type in(3,4,5) then 1 else 0 end) as turnOutCount   
  FROM
    tb_gongdan_detail a LEFT JOIN tb_gongdan_history b ON a.id=b.gongdan_id  

查出来的结果是这样的:
图片说明


现在,我有一个存放id的list,我想在SQL中的多个条件里foreach这个list,并且保证在每个条件中遍历的值都是同步进行的

List<String> idList

求教大佬这样的循环sql怎么写 ,跪谢大佬orz....

注:
①普通的foreach我会写,请不要无脑的丢一个foreach教程;
②请不要让我在java后台中每次传一个id循环调sql,这种方法没法用,不符合代码规范;

  • 写回答

3条回答 默认 最新

  • dabocaiqq 2019-08-13 09:27
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值