【JPA】SpringBootJPA使⽤GroupBy进⾏分组查询⾸先建⽴⼀个实体 装数据⽤
public class OrderGoods {
private Goods goods;
private Integer year = 0; //年份
private Integer month = 0;//⽉份
private Integer day=0; //⽇期
private Double num =0d;//该商品数量
}
其次Repository
groupby分组@RestResource(exported = false)
@Query("select sum(t.num) as ds as goods from OrderformDetail t group ds")
List findGroupByGoods();
很简单 就是在订单详细表中 按商品分组 列出商品数量 ⽅便进货
然后在Service 中
List<OrderGoods> list = new ArrayList<>();
List _list = dao.findGroupByGoods();
for(Object row:_list){
Object[] cells = (Object[]) row;
OrderGoods orderGoods = new OrderGoods();
orderGoods.setNum((Double) cells[0]);
orderGoods.setGoods((Goods) cells[1]);
list.add(orderGoods);
}
return list;
关键语句
Object[] cells = (Object[]) row;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论