一些有的没得小知识

1. 空间函数 st_distance_sphere / st_distance 计算距离

st_distance在mysql5.6+加入的;st_distance_sphere 在mysql5.7+加入的

在这里插入图片描述

通过经纬度查询距目标(113.8064049, 22.7300434)最近的五个地点,详情可见链接:参考链接

SELECT city,distance FROM (SELECT *, ST_DISTANCE_SPHERE(point (113.8064049, 22.7300434),point(longitude,latitude)) AS DISTANCE FROM data_point) A
ORDER BY distance ASC LIMIT 5
2. Stream流将List转Map
List<ContentVO> vos = contentService.findContentServicePage(vo);

Map<String, List<ContentVO>> listMap = vos.stream().collect(Collectors.groupingBy(ContentVO::getName));

Map<String, ContentVO> voMap = vos.stream().collect(Collectors.toMap(ContentVO::getName, Function.identity()));
// key 冲突时后者进行覆盖
Map<String, ContentVO> contentVOMap = vos.stream().collect(Collectors.toMap(ContentVO::getName, Function.identity(), (oldValue, newValue) -> newValue));

Map<String, String> stringMap = vos.stream().collect(Collectors.toMap(ContentVO::getName, ContentVO::getSubTitle));
Map<String, String> collect = vos.stream().collect(Collectors.toMap(ContentVO::getName, ContentVO::getSubTitle, (oldValue, newValue) -> newValue));

3. 批量连表更新:

举个例子:将下表的business_id值刷到supplier_branch_id字段

在这里插入图片描述

刷数据SQL脚本如下:

  • 通过UPDATE 和INNER JOIN 进行连表更新即可,明确号关联条件
  • 当然也可以用CASE WHEN 的形式,当没有这种语法方便
UPDATE `t_process_instance` a
INNER JOIN (
SELECT b.id , b.business_id FROM t_process_instance b WHERE b.process_type = 23
) c ON a.id = c.id
SET a.supplier_branch_id = c.business_id
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值