当前位置:网站首页>SQL and list de duplication
SQL and list de duplication
2022-06-28 05:58:00 【Abiotic linguist】
One 、sql Use scenarios 1: The last approval reason corresponding to the paging query task
1、 Query master sql: Use the main table task Link the audit record table resion
SELECT * FROM task t LEFT JOIN resion r ON t.id=r.task_id LEFT JOIN xxxtable;2、 Problem analysis : One task corresponds to multiple approval records , Linked queries produce Cartesian products , Result set error . Yes sql To transform
SELECT
*
FROM
task t
LEFT JOIN (
SELECT
r.*
FROM
resion r
INNER JOIN ( SELECT task_id, max( create_time ) create_time FROM resion GROUP BY task_id ) a ON a.task_id = r.task_id
AND a.create_time = r.create_time
) e ON e.task_id = t.task_id3、 Optimize : When two audit records appear at the same time, data set errors cannot be avoided , Therefore, you can add additional conditions to ensure the uniqueness of the schedule
SELECT
*
FROM
task t
LEFT JOIN (
SELECT
r.*
FROM
(
SELECT
a.*,
count( 1 ) onlyValue
FROM
resion a
INNER JOIN resion b ON a.task_id = b.task_id
AND a.create_time <= b.create_time
GROUP BY
a.resion_id
) r
WHERE
r.onlyValue = 1
) e ON e.task_id = t.task_idTwo 、list To reprocess
1、 use TreeSet To and fro
1.1、 Two conversions
// Here is the raw data without weight removal
List<TaskInfo> taskList=...;
// according to id Attribute de duplication
Set<TaskInfo> taskSet = new TreeSet<>(Comparator.comparing(TaskInfo::getId));
taskSet.addAll(taskList);
taskList=new ArrayList<TaskInfo>(taskSet);1.2、 Flow conversion
List<TaskInfo> newList = taskList.stream().collect(Collectors
.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(TaskInfo::getId))),
ArrayList::new));1.3、 Multi attribute joint de duplication
Set<TaskInfo> taskSet = new TreeSet<>(Comparator.comparing(o -> (o.getId() + "" + o.getDeptId())));
taskSet .addAll(taskList);
taskList=new ArrayList<TaskInfo>(taskSet);2、 use map Handle
2.1、 filtration
List<TaskInfo> taskList = new ArrayList<>();
oldList.stream().filter(distinctByKey(t ->t.getId())).forEach(taskList::add);
static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Map<Object,Boolean> seen = new ConcurrentHashMap<>();
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}2.2、 The stream packet loop takes the first
边栏推荐
- 安装 Ffmpefg
- bash install. SH ******** error
- What is the e-commerce conversion rate so abstract?
- YYGH-6-微信登录
- Enum
- 数据中台:AI中台的实施与总结
- Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException:异常解决
- MR-WordCount
- Valueerror: iterative over raw text documents expected, string object received
- Video tutorial on website operation to achieve SEO operation [21 lectures]
猜你喜欢

ES9023音频解码芯片的工作原理

Valueerror: iterative over raw text documents expected, string object received

Binder interview: memory management unit

Shanghai Yuge ASR CAT1 4G module 2-way low power 4G application

Deep learning 19 loss functions

How the third-party libraries in cocoapod reference local header files

death_satan/hyperf-validate
![[C language practice - printing hollow square and its deformation]](/img/59/9122a6c8437f12bc28c97304ba9787.png)
[C language practice - printing hollow square and its deformation]

高质量国产立体声编解码器CJC8988,Pin to Pin替代WM8988

RL 实践(0)—— 及第平台辛丑年冬赛季【Rule-based policy】
随机推荐
Ape pink ape power - Developer activity attack!
CSI以及本地盘的相关实现记录
Xcode13.3.1 项目执行pod install后报错
Xcode13.3.1 error reported after pod install
阿里云短信服务(完整指南),短信发送功能实现。
Mysql-16-subquery
数据仓库:DWS层设计原则
Data midrange: implementation and summary of AI midrange
Sklearn Feature Engineering (summary)
pytorch dataloader的长度 epoch与iteration的区别
Shanghai Yuge ASR CAT1 4G module 2-way low power 4G application
数据中台:数据治理的七把利剑
Maskrcnn, fast RCNN, fast RCNN excellent video
6. 毕业设计温湿度监控系统(ESP8266 + DHT11 +OLED 实时上传温湿度数据给公网服务器并在OLED显示屏上显示实时温湿度)
[MySQL] all query tables contain 20million data -- how to optimize SQL
6. graduation design temperature and humidity monitoring system (esp8266 + DHT11 +oled real-time upload temperature and humidity data to the public network server and display the real-time temperature
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance
Bidirectional level conversion circuit
数据仓库:分层设计详解
Ethereum Classic的难度计算|猿创征文