当前位置:网站首页>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
边栏推荐
- High quality domestic stereo codec cjc8988, pin to pin replaces wm8988
- Data warehouse: DWS layer design principle
- Introduction to uicollectionviewdiffabledatasource and nsdiffabledatasourcesnapshot
- 容量调度绝对值配置队列使用与避坑
- 联想混合云Lenovo xCloud,新企业IT服务门户
- How to add live chat in your Shopify store?
- 6. 毕业设计温湿度监控系统(ESP8266 + DHT11 +OLED 实时上传温湿度数据给公网服务器并在OLED显示屏上显示实时温湿度)
- Install fmpefg
- Error: the following arguments are required:
- Typescript interface
猜你喜欢
随机推荐
qtcanpool 知 07:Ribbon
Data middle office: an article that takes you to understand data middle office in simple terms
Ape pink ape power - Developer activity attack!
ERP软件公司选型的重要根据
Mysql-16-subquery
YYGH-6-微信登录
Main functions of 5ggnb and ng ENB
Xcode13.3.1 项目执行pod install后报错
pytorch dataloader的长度 epoch与iteration的区别
【无标题】
[CAD drawing Video] AutoCAD 2014 master's way
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
使用SSM框架,配置多个数据库连接
Oracle condition, circular statement
猿粉猿动力-开发者活动袭!
Cryptography notes
高质量国产立体声编解码器CJC8988,Pin to Pin替代WM8988
数据中台:六问数据中台
Global country (and region) information JSON data
移动广告发展动向:撬动存量,精细营销









